instructure/canvas-lms · error · StandardError

validation_error_filename

Error message

validation_error_filename

What it means

ImgAltRuleHelper rejects alt text that looks like a filename (via filename_like?). Filenames such as 'image.png' or 'IMG_1234.jpg' are not meaningful alt text, so the accessibility rule raises StandardError with the validation_error_filename message to force the author to describe the image instead.

Solutions

  1. Replace the filename with a human description of the image's content
  2. Adjust input so the user cannot submit while the value matches the filename heuristic
  3. If the heuristic false-positives on legitimate text, rewrite the value so it doesn't match the pattern (e.g. remove extension-like suffix)
  4. Rescue the error and re-prompt the user for a description

Example fix

// before
fix(elem, 'IMG_2049.jpg')
// after
fix(elem, 'Students collaborating in a lab')
Defensive patterns

Strategy: validation

Validate before calling

const FILENAME_RE = /\.[a-z0-9]{2,4}$/i;
if (FILENAME_RE.test(alt_text.trim())) {
  alert('Describe the image, do not use the file name'); return;
}
submitFix(elem, alt_text)

Type guard

const isDescriptive = (v) => typeof v === 'string' && v.trim().length > 0 && !/\.\w{2,4}$/.test(v.trim())

Try / catch

begin
  helper.fix(elem, value)
rescue StandardError => e
  flash[:error] = e.message
  redirect_back
end

Prevention

When it happens

Trigger: Calling the img alt fix with a value that filename_like? classifies as a filename (e.g. contains extensions like .png/.jpg, CamelCase-with-digits patterns); user pastes the uploaded file's name into the alt field.

Common situations: Course authors leaving the default filename in the alt text box; bulk migration scripts copying title attributes containing file names into alt; CMS imports preserving original upload names.

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


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

Appendix: source

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

      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)