instructure/canvas-lms · error · ArgumentError
Invalid value for form: #
Error message
Invalid value for form: #{value} What it means
HeadingsStartAtH2Rule#fix! only accepts values equal to the translated strings 'Change heading level to Heading 2' or 'Turn into a paragraph' and rewrites the element tag accordingly. Any other value raises ArgumentError 'Invalid value for form: ...' since the fixer cannot infer the intended transformation.
Solutions
- Pass the exact I18n.t('Change heading level to Heading 2') or I18n.t('Turn into a paragraph') string as value, computed in the same locale as the request
- Better: compare against stable keys instead of translated labels (refactor the rule to accept 'h2'/'p')
- Ensure I18n.locale is consistent between rendering the fix form and processing fix!
- Rescue ArgumentError and return a 400 with the accepted options
Example fix
// before
rule.fix!(elem, 'Change heading level to Heading 2') # fails in non-en locale
// after
rule.fix!(elem, I18n.t('Change heading level to Heading 2')) Defensive patterns
Strategy: validation
Validate before calling
// send stable keys, compare in the same locale
const accepted = [I18n.t('Change heading level to Heading 2'), I18n.t('Turn into a paragraph')];
if (!accepted.includes(value)) return alert('Invalid option'); Try / catch
begin
rule.fix!(elem, value)
rescue ArgumentError => e
render json: { error: e.message, accepted: ['h2','p'] }, status: :bad_request
end Prevention
- Never hard-code English labels in clients; compute via I18n.t at submit time
- Pin I18n.locale for the request lifecycle (render + submit in same locale)
- Refactor the rule to accept semantic keys ('h2'/'p') rather than translated strings
When it happens
Trigger: Calling fix! with a value that doesn't byte-equal the current I18n.t translations, e.g. hard-coded English strings in a non-English locale, or a value key like 'h2' instead of the label; locale changed between form render and submission.
Common situations: Locale mismatch: page rendered in English, submitted under a different I18n.locale (per-user locale), so value compares false; tests passing raw English labels while specs run in another locale; API clients sending semantic values instead of labels.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Caption cannot be empty.
- Invalid scope value. Valid options are: #
- validation_error_filename
- validation_error_missing
- validation_error_too_long
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/84970f2994a04288.
Report an issue: GitHub.
Appendix: source
Thrown at app/models/accessibility/rules/headings_start_at_h2_rule.rb:52
label: I18n.t("How would you like to proceed?"),
undo_text: I18n.t("Reformatted"),
value: I18n.t("Change heading level to Heading 2"),
action: I18n.t("Reformat"),
options: [
I18n.t("Change heading level to Heading 2"),
I18n.t("Turn into a paragraph")
]
)
end
def fix!(elem, value)
case value
when I18n.t("Change heading level to Heading 2")
elem.name = "h2"
when I18n.t("Turn into a paragraph")
elem.name = "p"
else
raise ArgumentError, "Invalid value for form: #{value}"
end
{ changed: elem }
end
def display_name
I18n.t("Heading levels should start at level 2")
end
def message
I18n.t(
"This text is styled as a Heading 1, but there should only be one H1 on a web page — the page title. " \
"Use Heading 2 or lower (H2, H3, etc.) for your content headings instead."
)
end
def why
[
I18n.t(View on GitHub (pinned to 1c9f0bb801)