instructure/canvas-lms · error · StandardError

validation_error_too_long

Error message

validation_error_too_long

What it means

ImgAltRuleHelper enforces MAX_LENGTH on alt text; values longer than the limit raise StandardError with validation_error_too_long. Screen readers announce the entire alt string, so excessively long alt text is considered an accessibility failure the fixer will not apply.

Solutions

  1. Shorten alt text to a concise description under MAX_LENGTH
  2. Move long descriptions to a caption, figure/figcaption, or longdesc and keep alt brief
  3. Truncate or validate client-side with a maxlength attribute before submitting
  4. Rescue the error and return a message indicating the maximum allowed length

Example fix

// before
fix(elem, long_paragraph_300_chars)
// after
fix(elem, long_paragraph_300_chars[0, MAX_LENGTH].sub(/\s\S*$/, ''))
Defensive patterns

Strategy: validation

Validate before calling

const MAX_LENGTH = 120; // match rule's MAX_LENGTH
if (alt_text.length > MAX_LENGTH) {
  alert(`Alt text must be at most ${MAX_LENGTH} characters`); return;
}

Type guard

const withinLimit = (v, max) => typeof v === 'string' && v.length <= max

Try / catch

begin
  helper.fix(elem, value)
rescue StandardError => e
  render json: { error: e.message, max_length: described_limit }, status: :unprocessable_entity
end

Prevention

When it happens

Trigger: Calling the img alt fix with value.length > MAX_LENGTH; user pastes a paragraph or long caption into the alt field; bulk fixer passing untruncated descriptions.

Common situations: Authors pasting long descriptions or entire documents into alt text; automated content migrations not enforcing a length cap; localized strings that balloon in length.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/35e7ed8ca7275d43. Report an issue: GitHub.

Appendix: source

Thrown at app/models/accessibility/rules/img_alt_rule_helper.rb:69

      end

      def self.fix_alt_text!(elem, value)
        if value.nil?
          elem["role"] = "presentation"
          elem["alt"] = ""
          return { changed: elem, content_preview: adjust_img_style(elem) }
        end

        if value.to_s.strip.empty?
          raise StandardError, validation_error_missing
        end

        if filename_like?(value)
          raise StandardError, validation_error_filename
        end

        if value.length > MAX_LENGTH
          raise StandardError, validation_error_too_long
        end

        elem["alt"] = value
        { changed: elem, content_preview: adjust_img_style(elem) }
      end
    end
  end
end

View on GitHub (pinned to 1c9f0bb801)