{"record":{"id":"35e7ed8ca7275d43","repo":"instructure/canvas-lms","slug":"validation-error-too-long","errorCode":null,"errorMessage":"validation_error_too_long","messagePattern":"validation_error_too_long","errorType":"validation","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"app/models/accessibility/rules/img_alt_rule_helper.rb","lineNumber":69,"sourceCode":"      end\n\n      def self.fix_alt_text!(elem, value)\n        if value.nil?\n          elem[\"role\"] = \"presentation\"\n          elem[\"alt\"] = \"\"\n          return { changed: elem, content_preview: adjust_img_style(elem) }\n        end\n\n        if value.to_s.strip.empty?\n          raise StandardError, validation_error_missing\n        end\n\n        if filename_like?(value)\n          raise StandardError, validation_error_filename\n        end\n\n        if value.length > MAX_LENGTH\n          raise StandardError, validation_error_too_long\n        end\n\n        elem[\"alt\"] = value\n        { changed: elem, content_preview: adjust_img_style(elem) }\n      end\n    end\n  end\nend\n","sourceCodeStart":51,"sourceCodeEnd":78,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/accessibility/rules/img_alt_rule_helper.rb#L51-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"Authors pasting long descriptions or entire documents into alt text; automated content migrations not enforcing a length cap; localized strings that balloon in length.","solutions":["Shorten alt text to a concise description under MAX_LENGTH","Move long descriptions to a caption, figure/figcaption, or longdesc and keep alt brief","Truncate or validate client-side with a maxlength attribute before submitting","Rescue the error and return a message indicating the maximum allowed length"],"exampleFix":"// before\nfix(elem, long_paragraph_300_chars)\n// after\nfix(elem, long_paragraph_300_chars[0, MAX_LENGTH].sub(/\\s\\S*$/, ''))","handlingStrategy":"validation","validationCode":"const MAX_LENGTH = 120; // match rule's MAX_LENGTH\nif (alt_text.length > MAX_LENGTH) {\n  alert(`Alt text must be at most ${MAX_LENGTH} characters`); return;\n}","typeGuard":"const withinLimit = (v, max) => typeof v === 'string' && v.length <= max","tryCatchPattern":"begin\n  helper.fix(elem, value)\nrescue StandardError => e\n  render json: { error: e.message, max_length: described_limit }, status: :unprocessable_entity\nend","preventionTips":["Set maxlength on the alt text input matching MAX_LENGTH","Keep long descriptions in figcaption or surrounding body text","Account for localization: translated strings may be longer"],"tags":["accessibility","validation","length-limit"],"backgroundTag":"value-out-of-range","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}