instructure/canvas-lms · error · StandardError

validation_error_missing

Error message

validation_error_missing

What it means

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.

Solutions

  1. Provide non-empty alt text when calling the fix method
  2. Trim and check value.to_s.strip.empty? on the client before submitting the fix
  3. If the image is decorative, use the decorative/presentation path instead of an empty manual value
  4. Rescue StandardError in the fixer controller and surface validation_error_missing to the user

Example fix

// before
fix(elem, '')
// after
fix(elem, 'Chart showing Q3 enrollment growth') unless alt_text.strip.empty?
Defensive patterns

Strategy: validation

Validate before calling

if alt_text.to_s.strip.empty?
  alert('Alt text is required'); return;
end
submitFix(elem, alt_text)

Type guard

const hasAlt = (v) => typeof v === 'string' && v.trim().length > 0

Try / catch

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

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

      end

      def self.validation_error_filename
        I18n.t("Alt text can not be a filename.")
      end

      def self.validation_error_too_long
        I18n.t("Keep alt text under %{max_length} characters.", max_length: MAX_LENGTH)
      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)