{"record":{"id":"83d240111c1f0cab","repo":"instructure/canvas-lms","slug":"rate-limit-must-be-either-nil-or-hash-with-limit-and-period","errorCode":null,"errorMessage":"Rate limit must be either nil, or hash with :limit and :period keys","messagePattern":"Rate limit must be either nil, or hash with :limit and :period keys","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"app/models/llm_config.rb","lineNumber":65,"sourceCode":"        new_options[key] = value.gsub(\"<#{placeholder_prefix}_PLACEHOLDER>\", sub_value.to_s) if value.is_a?(String)\n      end\n    end\n\n    new_options.each_value do |value|\n      if value.is_a?(String) && (remaining_placeholder = value.match(/<\\w+_PLACEHOLDER>/))\n        raise ArgumentError, \"Options still contain placeholder: #{remaining_placeholder[0]}\"\n      end\n    end\n\n    [new_template, new_options]\n  end\n\n  private\n\n  def validate!\n    raise ArgumentError, \"Name must be a string\" unless @name.is_a?(String)\n    raise ArgumentError, \"Model ID must be a string\" unless @model_id.is_a?(String)\n    raise ArgumentError, \"Rate limit must be either nil, or hash with :limit and :period keys\" unless @rate_limit.nil? || (@rate_limit.is_a?(Hash) && @rate_limit.keys == %i[limit period])\n    raise ArgumentError, \"Template must be a string\" unless @template.is_a?(String)\n    raise ArgumentError, \"Options must be a hash\" unless @options.is_a?(Hash)\n  end\nend\n","sourceCodeStart":47,"sourceCodeEnd":70,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/llm_config.rb#L47-L70","documentation":"LlmConfig#validate! raises ArgumentError unless rate_limit is nil or exactly a Hash with keys [:limit, :period] (in that order per keys == %i[limit period]). Any other shape — extra keys, missing keys, wrong types, or a different key order — is rejected.","triggerScenarios":"LlmConfig.new(name, model_id, rate_limit, ...) where rate_limit is a string, a hash with keys like {limit: n} only, keys in a different order, or containing extra keys.","commonSituations":"Config parsed from YAML where keys load as strings ('limit' vs :limit); adding new rate-limit fields the validator doesn't know; constructing the hash in a different key order.","solutions":["Pass exactly {limit: <int>, period: <symbol>} or nil.","If loading from YAML, symbolize keys and reorder/normalize to [:limit, :period].","Remove unsupported keys from the rate_limit hash."],"exampleFix":"// before\nLlmConfig.new(\"gpt4\", \"gpt-4\", {\"limit\" => 10, \"period\" => :minute}, template, {})\n// after\nLlmConfig.new(\"gpt4\", \"gpt-4\", {limit: 10, period: :minute}, template, {})","handlingStrategy":"validation","validationCode":"ok = rate_limit.nil? || (rate_limit.is_a?(Hash) && rate_limit.keys == %i[limit period])\nraise ArgumentError, \"bad rate_limit shape\" unless ok","typeGuard":"def valid_rate_limit?(rl) = rl.nil? || (rl.is_a?(Hash) && rl.keys == %i[limit period])","tryCatchPattern":"begin\n  cfg = LlmConfig.new(name, model_id, rate_limit, ...)\nrescue ArgumentError => e\n  Rails.logger.error(\"Invalid rate_limit: #{e.message}\")\n  raise\nend","preventionTips":["Build rate limits via a factory that always emits {limit:, period:} in that order","Symbolize and normalize hashes loaded from YAML before passing them in","Avoid adding ad-hoc keys to the rate_limit hash"],"tags":["argumenterror","validation","rate-limit"],"backgroundTag":"invalid-config-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"}