Skip to content

fix(api): name the offending fields on a validation error - #474

Merged
chodeus merged 2 commits into
mainfrom
fix/surface-validation-field-errors
Aug 7, 2026
Merged

fix(api): name the offending fields on a validation error#474
chodeus merged 2 commits into
mainfrom
fix/surface-validation-field-errors

Conversation

@chodeus

@chodeus chodeus commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

main.py's RequestValidationError handler normalises every 422 to the bare message "Validation error", with the per-field detail in data. apiCore reads only message, and callers toast that — so the detail is fetched, serialised, sent over the wire and thrown away.

The result: submit any form with a missing or malformed field, anywhere in CHUB, and you get two words that name nothing.

Found while looking at why the CL2K asset makers reject a title with no TMDB id — but the fix is app-wide, not specific to that.

Type of change

  • Bug fix (non-breaking)

What it does

describeError() folds the field paths into the message:

Validation error — tmdb_id: Field required
Validation error — gdrive_uploads.0.folder_id: Field required
Validation error — a: Field required; b: Field required; c: Field required (+2 more)
  • Drops the request-section prefix FastAPI prepends (body/query/path/header)
  • Keeps nested paths readable, including array indices
  • Caps at three fields and says how many were hidden, so a big form can't produce a wall of text
  • Non-validation errors are returned byte-identical, so no existing message changes

Testing

  • npm run lint, npx prettier --check (whole tree), npm run build → exit 0
  • npx vitest run → 45 passed (7 new)

The four behavioural tests were verified red against the previous bare-message behaviour. Also covered: a non-validation payload passing through unchanged, data that isn't a list falling back to the base message, and an empty/absent payload returning '' so the caller still gets the HTTP status line.

Checklist

  • Config schema updated if applicable — N/A
  • Frontend builds cleanly
  • No new DAPS references introduced
  • Docs / wiki drafts updated if behavior or shape changed — JSDoc on describeError
  • CHANGELOG entry — release-please picks this up from the fix(api): commit on main

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation error messages by identifying affected fields, including nested fields.
    • Removed unnecessary technical request details to make errors easier to understand.
    • Limited long lists of invalid fields to the first three entries, with an omission count.
    • Preserved meaningful server messages and provided clearer fallback text when details are unavailable.

The backend normalises every 422 to the bare message "Validation error" and puts
the per-field detail in `data` (main.py's RequestValidationError handler). apiCore
read only `message`, so that detail was fetched, serialised, sent, and discarded —
every form in the app reported two words and named nothing.

describeError() folds the field paths into the message: "Validation error —
tmdb_id: Field required". Drops FastAPI's request-section prefix (body/query/…),
keeps nested paths readable (gdrive_uploads.0.folder_id), caps the list at three
and says how many were hidden.

Non-validation errors are returned unchanged, so no other message shifts.
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b483ec21-5394-42d6-ab33-60e7470d90a4

📥 Commits

Reviewing files that changed from the base of the PR and between d0a25b2 and d9f1b2d.

📒 Files selected for processing (2)
  • frontend/src/utils/api/core.js
  • frontend/src/utils/api/core.test.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/src/utils/api/core.test.js
  • frontend/src/utils/api/core.js

📝 Walkthrough

Walkthrough

The API core now formats validation errors with field paths, removes request prefixes, and limits displayed fields. HTTP error handling uses this formatter before fallback messages. Tests cover validation, nested paths, truncation, malformed data, and empty payloads.

Changes

Validation Error Handling

Layer / File(s) Summary
Validation error formatter and coverage
frontend/src/utils/api/core.js, frontend/src/utils/api/core.test.js
describeError formats validation details, handles nested fields, truncates long lists, and returns empty output for unusable payloads. Tests cover valid and malformed details.
HTTP error integration
frontend/src/utils/api/core.js
HTTP errors use describeError before falling back to the response message or generic status text.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: including offending field names in API validation errors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/surface-validation-field-errors

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/utils/api/core.js`:
- Around line 105-111: Update the detail mapping in validation to ignore entries
whose msg is not a non-empty string, so validation([{}]) uses the base-message
fallback instead of emitting “is invalid.” Replace the current || fallback with
an explicit message check while preserving valid message handling and add a
regression test for validation([{}]).
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec25a878-be32-44ec-b6b3-e98ff9cf8be5

📥 Commits

Reviewing files that changed from the base of the PR and between 293eb57 and d0a25b2.

📒 Files selected for processing (2)
  • frontend/src/utils/api/core.js
  • frontend/src/utils/api/core.test.js

Comment thread frontend/src/utils/api/core.js
`d?.msg || 'is invalid'` turned an empty detail record into
"Validation error — is invalid": a field-less phrase that is strictly worse than
the base message it replaced. An empty-string msg took the same path.

Explicit type check instead of `||`, per the repo rule about falsy-but-valid
values. A malformed entry is dropped, so the message degrades to the base one;
valid entries alongside it are still named.
@chodeus

chodeus commented Aug 7, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chodeus
chodeus merged commit 24b7563 into main Aug 7, 2026
12 checks passed
@chodeus
chodeus deleted the fix/surface-validation-field-errors branch August 7, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant