Repository navigation
Conversation
Starting a personal import showed a toast that did not say what went wrong. A source that refused the credentials produced a v2 problem whose detail was "The request did not pass validation; see errors." with the reason only in errors[0].detail. An unreachable server, a TLS failure, or a Jellyfin address without a scheme became a 500 "An unexpected error occurred", because ErrInvalidInput and transport failures had no mapping. Map ErrInvalidInput wraps to 400 with their fixed message, and HTTP client transport failures to the upstream 502 with a reachability message. A bare ErrInvalidInput and database connection errors stay internal errors. Validate personal Jellyfin and Plex addresses with the rule admin sources already use, and repeat the member message in the v2 problem detail so clients that show only the detail explain the failure. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
Warning Review limit reachedNext included review available in 24 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a992778e5d
ℹ️ 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".
| if !validBaseURL(strings.TrimSpace(input.PlexBaseURL)) { | ||
| return out, fmt.Errorf("%w: enter the Plex address with http:// or https:// at the start", ErrInvalidInput) | ||
| } | ||
| out.Credentials = personalRunCredentials{BaseURL: input.PlexBaseURL, ServerToken: input.PlexToken, AccountToken: firstNonEmpty(input.PlexAccountToken, input.PlexToken)} |
There was a problem hiding this comment.
Normalize the Plex URL before storing it
When a custom Plex address has leading or trailing whitespace, this validates the trimmed value but stores the original value in out.Credentials. enqueuePersonalRun later passes that untrimmed address to validateSource, which rejects it and returns ErrPersonalCredentialsUnavailable, so a valid copy-pasted URL produces a misleading 503 instead of starting the import. Store the trimmed URL or validate the exact value that will be stored.
AGENTS.md reference: AGENTS.md:L7-L9
Useful? React with 👍 / 👎.
| if !validBaseURL(strings.TrimSpace(input.JellyfinBaseURL)) { | ||
| return out, fmt.Errorf("%w: enter the Jellyfin address with http:// or https:// at the start", ErrInvalidInput) |
There was a problem hiding this comment.
Describe every rejected URL condition accurately
For an address such as https://server.example?token=x, or one containing user info or a fragment, validBaseURL rejects the input even though it already starts with https://; this response then tells the user to add a scheme, which cannot fix the request. The same misleading message is used for custom Plex addresses. Distinguish a missing/invalid scheme from the other forbidden components, or report the complete accepted URL rule.
AGENTS.md reference: AGENTS.md:L7-L9
Useful? React with 👍 / 👎.
| if historyImportSourceUnreachable(err) { | ||
| slog.Warn("history import: source server unreachable", "error", err) | ||
| return HistoryImportUnreachableAPIError() |
There was a problem hiding this comment.
Avoid duplicate error logs for mapped outages
When Emby Connect or plex.tv is unreachable, LoginEmbyConnect and CreatePlexPin log the failure at error level before calling this mapper, after which this new branch logs the same failure again at warning level. Those expected upstream outages therefore still trigger error-level alerts and now create duplicate records, contrary to the mapper's warning treatment; centralize the log here or remove the callers' unconditional error logs.
Useful? React with 👍 / 👎.
Problem
Related issue: #1243
When a personal history import could not start, the web page showed a toast that did not say why:
http://orhttps://The v2 problem for a refused login carried the reason only in
errors[0].detail, which the web toast does not show. Transport failures andhistoryimport.ErrInvalidInputhad no mapping at all, so they became a 500 and an error log line. The old string check inlooksLikeValidationErrorno longer matches the current Jellyfin message.Approach
ErrInvalidInputwraps to 400 with their message. Every wrap site uses a fixed string. A bareErrInvalidInputmarks an internal invariant in the personal queue, so it stays a logged 500.*url.Errorthatnet/httpreturns, so a Silo database connection failure, which pgx also reports as*net.OpError, stays a logged 500. The v2 surface already turns upstream 5xx into 503dependency_unavailablewithRetry-After: 30.validBaseURL. Before this, a malformed Plex address surfaced as "Personal imports are unavailable."validation_failedproblemdetailnow repeats the message inerrors[0].detail. Fixing this on the server covers every client that shows the problem detail, so the web, Apple, and Android clients need no change. Changing only the web toast to readerrors[]would fix one client.After this change the same three cases show:
docs/admin-api.mddocuments these responses forPOST /api/v2/history-imports/runs.Validation
ErrInvalidInput, a bare sentinel (stays 500), an unreachable source through*url.Error(502, upstream), and a pgx-shaped*net.OpErrorwithout*url.Error(stays 500). The v2 tests now assert thatdetailmatcheserrors[0].detail.*url.Errorguard from review); the handler tests cover their final text and status.CONTRIBUTING.mdran on this change combined with fix(historyimport): import Jellyfin favorites and support Jellyfin 12 #1331, before the two were split and before the review fixes below: build,gofmt,go vet,make lint-changed, the Postgres-backed history-import cancellation tests, the web checks, and everyverify-*target passed.make test-gofailed only inTestAdminResourceCapabilitiesAndScope, which fails the same way onmainon macOS, and ininternal/policy25 ms evaluation timeouts under full-suite load.internal/policypasses when run alone.make verify-local-pathscrashed with a bus error under the local GNU Make 3.81. The script passes when run directly and throughmakewith a clean environment.make lint-changedreports 0 issues, andgo test ./internal/historyimport/ ./internal/api/handlers/passes.go test ./internal/apiv2/fails only inTestAdminResourceCapabilitiesAndScope.Risks
/api/v1history-import routes. There, requests that returned 500 now return 400 (invalid input) or 502 (unreachable source) with the same error body shape. Everything else on v1 is unchanged. This is a fix that keeps the bridge usable, which the v1 freeze allows.Checklist
AI Disclosure
historyImportAPIError, including v1 and admin routes, probed error classification with real pgx connection errors, statement timeouts, and deadline errors, and checked the v2 fixtures and committed OpenAPI artifact. Findings for this PR:*url.Error, with a regression test.ErrInvalidInputfrom internal invariants would have become a silent 400. It stays a logged 500.🤖 Generated with Claude Code