fix: return validation error instead of 500 for out-of-range task_ids#2326
Open
mvanhorn wants to merge 1 commit into
Open
fix: return validation error instead of 500 for out-of-range task_ids#2326mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
Contributor
Author
|
Looked into the failing |
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.
Summary
Saving the "Create your own task pack" form with an out-of-range task id now shows an inline validation message instead of a 500. Ids like
999999999999999999parse fine in Elixir's arbitrary-precision integers, pass changeset validation, and then blow up insideRepo.insertwith a Postgrex "integer out of range" error; the form now rejects them at cast time.Why this matters
Reported in #1646 with three independent reproductions (2024-01, 2024-03, and 2026-07-06 on commit 2acd190).
Codebattle.TaskPackForm.cast_task_ids/2already rescuesString.to_integer/1failures for non-numeric input, but numeric input beyond PostgreSQL's int4 range reached the database and surfaced as a 500. The same path existed for update.Changes
cast_task_ids/2inapps/codebattle/lib/codebattle/forms/task_pack.exvalidates every parsed id is a positive integer within int4 range (1..2_147_483_647) and adds a changeset error in the same user-facing style as the existing parse-error message. The existing non-numeric rescue is unchanged, and no controller changes were needed:create/2andupdate/2already re-render the form when the changeset carries errors.Testing
Controller tests cover the non-numeric string case and the out-of-range integer case for both create and update, asserting the form re-renders with the validation message rather than raising.
Fixes #1646