{"record":{"id":"80756c020243d15a","repo":"instructure/canvas-lms","slug":"invalid-calculation-method-value","errorCode":null,"errorMessage":"invalid calculation_method: #{value}","messagePattern":"invalid calculation_method: #(.+?)","errorType":"validation","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/controllers/outcomes_academic_benchmark_import_api_controller.rb","lineNumber":120,"sourceCode":"  def valid_options(hash)\n    options = {}\n    if hash.key? :calculation_method\n      options[:calculation_method] = parse_calculation_method hash[:calculation_method]\n      options[:calculation_int] = parse_calculation_int options[:calculation_method], hash[:calculation_int]\n    end\n    options[:mastery_points] = parse_int hash[:mastery_points] if hash.key? :mastery_points\n    options[:points_possible] = parse_int hash[:points_possible] if hash.key? :points_possible\n    unless hash[:ratings].nil?\n      raise \"ratings expected to be an array\" unless hash[:ratings].is_a?(Array)\n\n      options[:ratings] = hash[:ratings].map { |r| parse_rating(r) }\n    end\n    options\n  end\n\n  def parse_calculation_method(value)\n    unless LearningOutcome.valid_calculation_method?(value)\n      raise \"invalid calculation_method: #{value}\"\n    end\n\n    value\n  end\n\n  def parse_calculation_int(calc_method, value)\n    int = value.nil? ? nil : parse_int(value)\n    unless LearningOutcome.valid_calculation_int?(int, calc_method)\n      raise \"invalid calculation_int: #{value}\"\n    end\n\n    int\n  end\n\n  def parse_rating(rating)\n    if rating.nil? || !rating.is_a?(ActionController::Parameters)\n      raise \"invalid ratings value: #{rating}\"\n    end","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/controllers/outcomes_academic_benchmark_import_api_controller.rb#L102-L138","documentation":"OutcomesAcademicBenchmarkImportApiController#parse_calculation_method validates the calculation_method against LearningOutcome.valid_calculation_method? and raises for anything unrecognized. Only the outcome calculation methods Canvas supports (e.g. decaying_average, n_mastery, latest, highest, average) are accepted.","triggerScenarios":"Supplying calculation_method in the import options hash with a value outside the supported set, misspelled, or in wrong case (e.g. 'DecayingAverage', 'decay_avg').","commonSituations":"Copy-pasting calculation method names from other LMS docs; plugins adding custom methods not present on the target install; sending the method's display label instead of its key.","solutions":["Use one of LearningOutcome's valid calculation methods: decaying_average, n_mastery, latest, highest, average.","Check LearningOutcome.valid_calculation_method?(value) or the CALCULATION_METHODS list before sending.","Use the snake_case key, not the human-readable label.","Confirm the target Canvas version supports the method (newer methods like average require recent versions)."],"exampleFix":"// before\n{ calculation_method: \"Decaying Average\" }\n// after\n{ calculation_method: \"decaying_average\", calculation_int: 65 }","handlingStrategy":"validation","validationCode":"raise ArgumentError unless %w[decaying_average n_mastery latest highest average].include?(calculation_method)","typeGuard":"def valid_method?(v) = LearningOutcome.valid_calculation_method?(v)","tryCatchPattern":"begin\n  import_outcomes(options)\nrescue RuntimeError => e\n  raise InvalidCalculationMethod, e.message if e.message.start_with?('invalid calculation_method:')\n  raise\nend","preventionTips":["Use snake_case method keys from LearningOutcome::CALCULATION_METHODS.","Check valid_calculation_method? before sending.","Don't send display labels or alternate LMS names.","Confirm method support on the target Canvas version."],"tags":["api","outcome","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}