Skip to content

Turn over-length registration answers into form errors, not 500s#1763

Merged
maebeale merged 1 commit into
mainfrom
maebeale/too-long-answer-form-error
Jun 19, 2026
Merged

Turn over-length registration answers into form errors, not 500s#1763
maebeale merged 1 commit into
mainfrom
maebeale/too-long-answer-form-error

Conversation

@maebeale

Copy link
Copy Markdown
Collaborator

Closes [link an issue or remove this line]

What is the goal of this PR and why is this important?

  • A public registration answer longer than its mapped varchar(255) column (e.g. a long city) raised ActiveRecord::ValueTooLong mid-registration and surfaced as a 500, with no way for the registrant to recover.
  • ValueTooLong is a StatementInvalid, which the service's existing RecordInvalid/RecordNotUnique rescues don't catch — so it escaped the normal "re-render the form with an error" path.

How did you approach the change?

  • EventRegistrationServices::PublicRegistration now rescues ActiveRecord::ValueTooLong and returns a failed result with a friendly, column-named message ("Your city is too long. Please shorten it and try again."). The controller already re-renders the form with that error, so it flows through as an ordinary form validation error.
  • The column can't always be mapped back to a single field (both the mailing and agency address write city), so the message names the column rather than guessing a field.

UI Testing Checklist

  • Submit the public registration form with an answer longer than its column (e.g. a 256-char city) → the form re-renders with "Your city is too long…", no 500, no registration created.

Anything else to add?

A registration answer longer than its mapped varchar(255) column (e.g. a long
city) raised ActiveRecord::ValueTooLong — a StatementInvalid, which the
service's RecordInvalid/RecordNotUnique rescues don't catch — so it surfaced as
a 500 mid-registration instead of letting the registrant correct it.

Rescue ValueTooLong in PublicRegistration and return a failed result with a
friendly, column-named message; the controller already re-renders the form with
that error. The column can't always be mapped back to a single field (mailing
and agency addresses both write `city`), so the message names the column.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Result.new(success?: true, event_registration: event_registration, form_submission: submission, errors: [])
end
rescue ActiveRecord::ValueTooLong => e
Result.new(success?: false, event_registration: nil, errors: [ too_long_message(e) ])

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 From Claude: ValueTooLong is a StatementInvalid, not a RecordInvalid, so it needs its own rescue — otherwise an answer longer than its varchar(255) column 500s mid-registration instead of re-rendering the form.

@maebeale maebeale marked this pull request as ready for review June 19, 2026 03:51
@maebeale maebeale requested a review from jmilljr24 June 19, 2026 03:59
@maebeale maebeale merged commit a2c78b3 into main Jun 19, 2026
3 checks passed
@maebeale maebeale deleted the maebeale/too-long-answer-form-error branch June 19, 2026 13:56
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.

2 participants