instructure/canvas-lms · error · ArgumentError

format must be one of #

Error message

format must be one of #{ACCEPTABLE_FORMAT_TYPES.join(",")}

What it means

accessible_date_format in ApplicationHelper translates a format name ('date', 'time', 'datetime') into a screenreader-friendly string via I18n. It guard-clauses with an ArgumentError because only ACCEPTABLE_FORMAT_TYPES are supported; anything else would silently produce a wrong or missing I18n key.

Solutions

  1. Pass only one of the accepted values: 'date', 'time', or 'datetime' (default)
  2. Check ACCEPTABLE_FORMAT_TYPES in app/helpers/application_helper.rb for the exact list before calling
  3. If a new format is genuinely needed, add it to ACCEPTABLE_FORMAT_TYPES and a matching 'when' branch with an I18n key
  4. Fix typos in the call site

Example fix

// before
accessible_date_format('calendar')
// after
accessible_date_format('date')
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, format unless ACCEPTABLE_FORMAT_TYPES.include?(format)

Try / catch

begin
  prompt = accessible_date_format(format)
rescue ArgumentError
  prompt = accessible_date_format('datetime')
end

Prevention

When it happens

Trigger: Calling accessible_date_format with a string outside ACCEPTABLE_FORMAT_TYPES, e.g. accessible_date_format('full') or a typo like 'datettime', or a caller forwarding an arbitrary UI-supplied format value.

Common situations: Adding a new datepicker variant and passing a new format name without updating ACCEPTABLE_FORMAT_TYPES; forwarding a param straight through to the helper; refactoring that renamed the accepted symbols.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at app/helpers/application_helper.rb:838

  end

  # used for generating a
  # prompt for use with date pickers
  # so it doesn't need to be declared all over the place
  def datepicker_screenreader_prompt(format_input = "datetime")
    prompt_text = I18n.t("#helpers.accessible_date_prompt", "Format Like")
    format = accessible_date_format(format_input)
    "#{prompt_text} #{format}"
  end

  ACCEPTABLE_FORMAT_TYPES = %w[date time datetime].freeze

  # useful for presenting a consistent
  # date format to screenreader users across the app
  # when telling them how to fill in a datetime field
  def accessible_date_format(format = "datetime")
    unless ACCEPTABLE_FORMAT_TYPES.include?(format)
      raise ArgumentError, "format must be one of #{ACCEPTABLE_FORMAT_TYPES.join(",")}"
    end

    case format
    when "date"
      I18n.t("#helpers.accessible_date_only_format", "YYYY-MM-DD")
    when "time"
      I18n.t("#helpers.accessible_time_only_format", "hh:mm")
    else
      I18n.t("#helpers.accessible_date_format", "YYYY-MM-DD hh:mm")
    end
  end

  # render a link with a tooltip containing a summary of due dates
  def multiple_due_date_tooltip(assignment, user, opts = {})
    user ||= @current_user
    presenter = OverrideTooltipPresenter.new(assignment, user, opts)
    render "shared/vdd_tooltip", presenter:
  end

View on GitHub (pinned to 1c9f0bb801)