{"record":{"id":"d20328ca9a8ea943","repo":"instructure/canvas-lms","slug":"name-must-be-a-string","errorCode":null,"errorMessage":"Name must be a string","messagePattern":"Name must be a string","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"app/models/llm_config.rb","lineNumber":63,"sourceCode":"    new_options.each do |key, value|\n      substitutions.each do |placeholder_prefix, sub_value|\n        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":45,"sourceCodeEnd":70,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/llm_config.rb#L45-L70","documentation":"LlmConfig#validate! runs at construction time and raises ArgumentError when the name passed to the initializer is not a String. The library requires every LLM config to carry a human-readable string name.","triggerScenarios":"LlmConfig.new(name: nil | symbol | integer | other non-string, ...) — i.e. any constructor call whose first argument is not a String.","commonSituations":"Loading config from YAML/JSON where name is absent or parsed as another type; passing symbols like :gpt4; dynamically generated configs with nil names.","solutions":["Pass the name as a String to LlmConfig.new.","Coerce at the config-loading boundary (e.g. cfg['name'].to_s or String(cfg['name'])).","Add schema validation to the YAML/JSON config file so missing names fail early."],"exampleFix":"// before\nLlmConfig.new(:gpt4, \"gpt-4\", nil, template, {})\n// after\nLlmConfig.new(\"gpt4\", \"gpt-4\", nil, template, {})","handlingStrategy":"type-guard","validationCode":"raise ArgumentError, \"name must be String\" unless name.is_a?(String)\ncfg = LlmConfig.new(name, ...)","typeGuard":"def valid_name?(v) = v.is_a?(String)","tryCatchPattern":"begin\n  cfg = LlmConfig.new(name, ...)\nrescue ArgumentError => e\n  Rails.logger.error(\"Invalid LlmConfig: #{e.message}\")\n  raise\nend","preventionTips":["Symbolize/normalize config files before constructing LlmConfig","Coerce with String(name) at load time","Validate YAML/JSON LLM config schema in CI"],"tags":["argumenterror","validation","llm-config"],"backgroundTag":"invalid-constructor-argument","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"}