instructure/canvas-lms · error · GraphQL::ExecutionError

invalid filter keys for announcements widget: #

Error message

invalid filter keys for announcements widget: #{invalid_keys.join(", ")}

What it means

The announcements widget filter hash only permits a single key, "filter". validate_announcements_filters! computes filters.keys - ["filter"] and raises this GraphQL::ExecutionError if any unexpected keys are present, protecting the stored widget config from unknown/typo'd fields.

Solutions

  1. Remove the extraneous keys so the announcements filters hash contains only "filter"
  2. If a new filter option is genuinely needed, add it to the allowed-keys subtraction in validate_announcements_filters! and persist it safely
  3. Confirm which widget you are targeting; other widgets allow different keys

Example fix

// before
filters: { "filter": "all", "sort": "date" }
// after
filters: { "filter": "all" }
Defensive patterns

Strategy: validation

Validate before calling

const allowedKeys = ["filter"];
const invalid = Object.keys(filters).filter((k) => !allowedKeys.includes(k));
if (invalid.length) throw new Error(`invalid filter keys for announcements widget: ${invalid.join(", ")}`);

Type guard

const hasOnlyFilterKey = (f) => f && Object.keys(f).every((k) => k === "filter");

Prevention

When it happens

Trigger: Sending a mutation for the announcements widget with filters containing any key besides "filter" (e.g. {"unreadOnly": true}, {"filter": "all", "sort": "date"}).

Common situations: Front-end code copy-pasted from another widget (course work uses selectedCourse/selectedDateFilter); adding a new filter key without updating the server-side whitelist; misspelled key names like "fitler".

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/162a932e31cdb88f. Report an issue: GitHub.

Appendix: source

Thrown at app/graphql/mutations/update_widget_dashboard_config.rb:108

      validate_todo_list_filters!(filters)
    elsif COURSE_WORK_WIDGET_IDS.include?(widget_id)
      validate_course_work_filters!(filters)
    else
      validate_generic_filters!(filters)
    end
  end

  def validate_announcements_filters!(filters)
    if filters.key?("filter")
      filter_value = filters["filter"]
      unless filter_value.is_a?(String) && VALID_ANNOUNCEMENT_FILTERS.include?(filter_value)
        raise GraphQL::ExecutionError, "filter must be one of: #{VALID_ANNOUNCEMENT_FILTERS.join(", ")}"
      end
    end

    invalid_keys = filters.keys - ["filter"]
    unless invalid_keys.empty?
      raise GraphQL::ExecutionError, "invalid filter keys for announcements widget: #{invalid_keys.join(", ")}"
    end
  end

  def validate_todo_list_filters!(filters)
    if filters.key?("filter")
      filter_value = filters["filter"]
      unless filter_value.is_a?(String) && VALID_TODO_FILTERS.include?(filter_value)
        raise GraphQL::ExecutionError, "filter must be one of: #{VALID_TODO_FILTERS.join(", ")}"
      end
    end

    invalid_keys = filters.keys - ["filter"]
    unless invalid_keys.empty?
      raise GraphQL::ExecutionError, "invalid filter keys for todo list widget: #{invalid_keys.join(", ")}"
    end
  end

  def validate_course_work_filters!(filters)

View on GitHub (pinned to 1c9f0bb801)