instructure/canvas-lms · error · StandardError

Caption cannot be empty.

Error message

Caption cannot be empty.

What it means

TableCaptionRule#fix! adds or updates a <caption> for a data table, but refuses to proceed when the provided caption value is blank, raising StandardError 'Caption cannot be empty.' A caption is required content for the fix, so an empty value cannot produce a valid accessibility correction.

Solutions

  1. Supply a non-blank caption string describing the table's purpose
  2. Disable the apply button until input is non-empty on the client
  3. If the table is layout-only, use a different rule (presentation role) instead of an empty caption
  4. Rescue StandardError around fix! and show the validation message

Example fix

// before
rule.fix!(table_elem, params[:caption]) # caption may be ''
// after
raise ValidationError, msg unless params[:caption].present?
rule.fix!(table_elem, params[:caption])
Defensive patterns

Strategy: validation

Validate before calling

if (!caption || !caption.trim()) {
  alert('Caption cannot be empty'); return;
}
rule.fix!(tableElem, caption)

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling fix!(elem, nil) or fix!(elem, '') or whitespace-only value on a table element; the a11y fixer UI submits the caption form with an empty text box.

Common situations: User clicks 'Generate'/'Apply' in the table caption fix dialog without typing; automated batch applying caption fixes with missing data; form reset clearing the input before submit.

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/19ba8215122a3a87. Report an issue: GitHub.

Appendix: source

Thrown at app/models/accessibility/rules/table_caption_rule.rb:48

        caption = elem.query_selector("caption")

        I18n.t("Table caption should be present.") if !caption || caption.text.gsub(/[[:space:]]/, "") == ""
      end

      def form(_elem)
        Accessibility::Forms::TextInputField.new(
          label: I18n.t("Table caption"),
          undo_text: I18n.t("Caption added"),
          value: "",
          action: I18n.t("Add caption"),
          can_generate_fix: true,
          generate_button_label: I18n.t("Generate")
        )
      end

      def fix!(elem, value)
        raise StandardError, "Caption cannot be empty." if value.blank?

        caption = elem.at_css("caption")
        unless caption
          caption = elem.document.create_element("caption")
          TableCaptionRuleHelper.prepend(elem, caption)
        end
        caption.content = value
        { changed: elem }
      end

      def display_name
        I18n.t("Missing table caption")
      end

      def message
        I18n.t("Tables should include a caption describing the contents of the table.")
      end

View on GitHub (pinned to 1c9f0bb801)