Repository navigation
fix(apiv2): answer invalid monitor options with 422 at the member - #4159
Merged
Merged
Conversation
Monitor create and edit answered an invalid mode, missing or out-of-range season_numbers, or a series_id that names a non-series item with 400 malformed_request and no errors[]. docs/downloads-api.md maps an invalid subscription option to 422 validation_failed with errors[].location naming the member, and malformed_request to malformed JSON only. Map each downloads error to validation_failed at its member: mode (invalid_enum, with the same detail create's schema gives), season_numbers (required or out_of_range), and series_id (invalid). POST /downloads with series=true on a non-series item gets the same treatment at content_id, so both download operations answer the same error alike. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (treats any non-200 from monitor create and edit as a failure and does not branch on the status); Android N/A (does not call the monitor routes, and its download creation does not branch on 400); Roku N/A (no downloads); Web N/A (does not call these routes)
Creating or editing a series monitor with an invalid option returns
400 malformed_requestwith noerrors[], so a client can't tell which field to fix. The downloads contract says an invalid subscription option is422 validation_failedwitherrors[].locationnaming the member, and thatmalformed_requestis for malformed JSON only. This change makes the monitor routes answer that way.The affected requests to
POST /api/v2/downloads/subscriptionsandPATCH /api/v2/downloads/subscriptions/{id}:mode: "specific_seasons"with noseason_numbers, on create or on an edit that switches to that modeseason_numbersentry below 0 or above 9999 (the schema has no per-item bound)modeon edit (the patch body'smodehas no schema enum; create's does)series_idthat names an item that is not a series, on createPOST /api/v2/downloadswithseries: truefor an item that is not a series had the same 400 and now gets the same 422 atcontent_id.Found in review of #4074.
Approach
subscriptionMutationProblemnow maps each downloads error to a validation failure at its member:ErrInvalidSubscriptionModebody.modeinvalid_enumErrSeasonsRequiredbody.season_numbersrequiredErrInvalidSeasonNumbersbody.season_numbersout_of_rangeErrNotSeriesbody.series_idinvalidAn unknown mode on edit gets the same code and detail that create's schema enum returns, and the test checks that the two match.
downloadCreationProblemmapsErrNotSeriestobody.content_idthe same way, so both download operations answer the same error alike.Adding the enum to the patch body's
modeschema would also catch an unknown mode, but it changes the generated contract that #3535 is editing, and the service check would still be needed. The OpenAPI already declares 422 for all three operations, so the contract artifacts don't change.Validation
mainwithstatus = 400, want 422and pass on this branch.go test ./internal/apiv2/... ./internal/downloads/...pass.go build ./...,go vet,gofmt,go mod tidy -diff,make lint-changed(0 issues), andmake lint-router-recoverypass.verify-apiv2-openapi,verify-apiv2-contract(no contract diff),verify-route-inventory,verify-apiv2-fixtures,TestCommittedArtifactMatchesRouter,verify-size-ratchet, andverify-local-pathspass.make test-go: passes except two tests that run the local FFmpeg (TestRunStatsWithRealFFmpeg,TestCopyRemuxSubtitleRenditionRealFFmpeg). Both fail the same way on unmodifiedmainon the test host.prepareSubscriptionandapplySubscriptionPatchreturn these errors, and by the handler tests above.Evidence
Trimmed test runs on the base and the branch, with the trigger-to-response table.
Evidence: https://evidence.siloserver.org/r/silo-server/monitor-options-422/
Risks
A client that branched on 400 for these requests would now take its 422 path. The Apple, Android, and web callers were checked and none branch on it. The status already matches what the downloads contract documents.
Checklist
AI Disclosure
/silocode review at high effort (three finders). It removed a test case that checked an edit response for an error the edit path cannot return. The plan round was skipped because the fix is mechanical: the defect is in a few mapping lines and adds nothing. A simplify pass aligned one error detail. A background adversarial review (gpt-6.1-sol, reviewed 11c9c4d) found nothing.🤖 Generated with Claude Code