instructure/canvas-lms · error

invalid ratings value: #

Error message

invalid ratings value: #{rating}

What it means

OutcomesAcademicBenchmarkImportApiController#parse_rating requires each rating entry to be a non-nil ActionController::Parameters object and raises otherwise. This ensures each mastery rating in the ratings array is a structured parameter object with description and points.

Solutions

  1. Send each rating as an object with description (string) and points (integer).
  2. If calling the controller helper directly from Ruby, wrap hashes in ActionController::Parameters.
  3. Filter out nil entries from the ratings array before submission.
  4. Validate each entry client-side before calling the API.

Example fix

// before
ratings: ["Mastery", "Near"]
// after
ratings: [{ description: "Mastery", points: 3 }, { description: "Near", points: 2 }]
Defensive patterns

Strategy: type-guard

Validate before calling

raise ArgumentError unless ratings.all? { |r| r.is_a?(ActionController::Parameters) }

Type guard

def rating_param?(r) = !r.nil? && r.is_a?(ActionController::Parameters)

Try / catch

begin
  import_outcomes(options)
rescue RuntimeError => e
  raise InvalidRatingEntry, e.message if e.message.start_with?('invalid ratings value:')
  raise
end

Prevention

When it happens

Trigger: Passing a rating entry that is a plain hash, string, number, or nil inside the :ratings array — e.g. ratings: ['Mastery'] or ratings: [nil].

Common situations: Sending plain JSON objects that arrive as Hash/HashWithIndifferentAccess rather than ActionController::Parameters depending on the call path; array of strings from a simplified form; nil entries from sparse data.

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/1c844bb9dd5b365b. Report an issue: GitHub.

Appendix: source

Thrown at app/controllers/outcomes_academic_benchmark_import_api_controller.rb:137

    unless LearningOutcome.valid_calculation_method?(value)
      raise "invalid calculation_method: #{value}"
    end

    value
  end

  def parse_calculation_int(calc_method, value)
    int = value.nil? ? nil : parse_int(value)
    unless LearningOutcome.valid_calculation_int?(int, calc_method)
      raise "invalid calculation_int: #{value}"
    end

    int
  end

  def parse_rating(rating)
    if rating.nil? || !rating.is_a?(ActionController::Parameters)
      raise "invalid ratings value: #{rating}"
    end
    if rating[:description].nil? || !rating[:description].is_a?(String)
      raise "invalid description value: #{rating[:description]}"
    end

    { description: rating[:description], points: parse_int(rating[:points]) }
  end
end

View on GitHub (pinned to 1c9f0bb801)