{"record":{"id":"9987df3008003087","repo":"instructure/canvas-lms","slug":"validation-error-missing","errorCode":null,"errorMessage":"validation_error_missing","messagePattern":"validation_error_missing","errorType":"validation","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"app/models/accessibility/rules/img_alt_rule_helper.rb","lineNumber":61,"sourceCode":"      end\n\n      def self.validation_error_filename\n        I18n.t(\"Alt text can not be a filename.\")\n      end\n\n      def self.validation_error_too_long\n        I18n.t(\"Keep alt text under %{max_length} characters.\", max_length: MAX_LENGTH)\n      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":43,"sourceCodeEnd":78,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/accessibility/rules/img_alt_rule_helper.rb#L43-L78","documentation":"ImgAltRuleHelper's fix method validates a user-provided alt text value for an <img> element. When the value is blank or only whitespace (and the image was not already handled as decorative), it raises StandardError with an i18n-translated 'missing' message. The accessibility fixer refuses to apply an empty alt attribute because the whole point of the fix is to supply meaningful alternative text.","triggerScenarios":"Calling the img alt fix (fix) with value = '' or value = '   ' (whitespace only) for a non-decorative image; a UI form submits the accessibility fix with an untouched/empty alt input field.","commonSituations":"A user clicks the accessibility fix button in the RCE a11y checker and submits without typing alt text; an automated fix batch passes blank values; localization bug makes I18n.t return an empty string for the value-matching path.","solutions":["Provide non-empty alt text when calling the fix method","Trim and check value.to_s.strip.empty? on the client before submitting the fix","If the image is decorative, use the decorative/presentation path instead of an empty manual value","Rescue StandardError in the fixer controller and surface validation_error_missing to the user"],"exampleFix":"// before\nfix(elem, '')\n// after\nfix(elem, 'Chart showing Q3 enrollment growth') unless alt_text.strip.empty?","handlingStrategy":"validation","validationCode":"if alt_text.to_s.strip.empty?\n  alert('Alt text is required'); return;\nend\nsubmitFix(elem, alt_text)","typeGuard":"const hasAlt = (v) => typeof v === 'string' && v.trim().length > 0","tryCatchPattern":"begin\n  ImgAltRuleHelper.fix(elem, value)\nrescue StandardError => e\n  render json: { error: e.message }, status: :unprocessable_entity\nend","preventionTips":["Require the alt input field in the fix dialog (HTML required + server recheck)","Offer a separate explicit 'decorative image' toggle instead of allowing empty alt","Trim input server-side before validation"],"tags":["accessibility","validation","ruby"],"backgroundTag":"empty-required-field","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"}