Skip to content

feat: validate numeric custom fields during import#2152

Merged
DonKoko merged 8 commits intomainfrom
codex/improve-asset-import-error-handling
Oct 28, 2025
Merged

feat: validate numeric custom fields during import#2152
DonKoko merged 8 commits intomainfrom
codex/improve-asset-import-error-handling

Conversation

@DonKoko
Copy link
Copy Markdown
Contributor

@DonKoko DonKoko commented Oct 28, 2025

Summary

  • sanitize AMOUNT and NUMBER inputs in buildCustomFieldValue and surface descriptive validation errors
  • validate and sanitize imported numeric custom fields in createAssetsFromContentImport, adding actionable error handling for bad data and DB constraint fallbacks
  • add Vitest coverage for numeric sanitization logic and asset import error messaging

Testing

  • npx vitest run test/utils/custom-fields.test.ts test/modules/asset/create-assets-from-content-import.test.ts

https://chatgpt.com/codex/tasks/task_b_68efb543f8bc8320a3a3443ee24449ac

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
shelf-docs Ignored Ignored Preview Oct 28, 2025 11:34am

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/utils/custom-fields.ts Outdated
@Shelf-nu Shelf-nu deleted a comment from coderabbitai bot Oct 28, 2025
- Remove unhelpful heavily-mocked integration test that didn't test
  real behavior
- Reject thousand separators in AMOUNT/NUMBER fields (e.g., 1,234
  or 1,234.56) with specific error messages
- Add smart heuristic to detect thousand separators: reject if
  exactly 3 digits follow a single separator
- Restructure error messages for clarity: show specific reason
  first, then actionable guidance
- Update error guidance to accurately reflect that currency symbols
  are automatically removed, not forbidden
- Add comprehensive test coverage for edge cases: plain numbers,
  decimals, negatives, zeros, and all rejection scenarios
- Preserve original error context when adding asset information
  during import
@DonKoko DonKoko requested a review from Copilot October 28, 2025 10:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds validation and sanitization for numeric custom fields (AMOUNT and NUMBER types) during asset import to prevent invalid data and provide clear error messages to users.

Key Changes:

  • Implements sanitizeNumericInput function to validate and normalize numeric values with support for various formats (decimals, negatives, currency symbols) while rejecting invalid formats (thousand separators, scientific notation)
  • Enhances error handling in createAssetsFromContentImport to catch validation errors and provide asset-specific context in error messages
  • Adds comprehensive test coverage for numeric validation logic

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
test/utils/custom-fields.test.ts New test file with 196 lines covering numeric sanitization edge cases including valid formats, invalid formats, and error scenarios
app/utils/custom-fields.ts Adds sanitizeNumericInput function with detailed validation logic and updates buildCustomFieldValue to use it for AMOUNT/NUMBER fields
app/modules/asset/service.server.ts Refactors custom field processing in createAssetsFromContentImport with enhanced error handling for numeric fields and database constraint failures

Comment thread app/utils/custom-fields.ts Outdated
Comment thread app/utils/custom-fields.ts
Comment thread app/modules/asset/service.server.ts Outdated
Comment thread app/modules/asset/service.server.ts Outdated
Comment thread app/modules/asset/service.server.ts
DonKoko and others added 6 commits October 28, 2025 11:34
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Address code review feedback:
- Replace fragile string-based check (includes "(asset: '")) with
  robust additionalData check for assetKey presence
- Use regex with capture group instead of simple replace() to
  precisely insert asset context after field name, avoiding issues
  with multiple occurrences
- Simplify test type definition to avoid Omit<> complexity

This makes the error context injection more maintainable and less
coupled to message format.
- Forward generic type parameter T to underlying useFetcher call
- Update import-content to use useFetcherWithReset with SerializeFrom
- Add reset functionality to AlertDialog onOpenChange to clear form
  state when dialog is closed

This ensures proper TypeScript inference when using the hook with
typed actions.
@DonKoko DonKoko merged commit cef6ba4 into main Oct 28, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants