{"record":{"id":"a09a0527bc25888d","repo":"ruby/ruby","slug":"dependency-name-must-be-a-string-was-name-inspe","errorCode":null,"errorMessage":"dependency name must be a String, was #{name.inspect}","messagePattern":"dependency name must be a String, was #(.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/rubygems/dependency.rb","lineNumber":44,"sourceCode":"  ##\n  # Allows you to force this dependency to be a prerelease.\n\n  attr_writer :prerelease\n\n  ##\n  # Constructs a dependency with +name+ and +requirements+. The last\n  # argument can optionally be the dependency type, which defaults to\n  # <tt>:runtime</tt>.\n\n  def initialize(name, *requirements)\n    case name\n    when String then # ok\n    when Regexp then\n      msg = [\"NOTE: Dependency.new w/ a regexp is deprecated.\",\n             \"Dependency.new called from #{Gem.location_of_caller.join(\":\")}\"]\n      warn msg.join(\"\\n\") unless Gem::Deprecate.skip\n    else\n      raise ArgumentError,\n            \"dependency name must be a String, was #{name.inspect}\"\n    end\n\n    type         = Symbol === requirements.last ? requirements.pop : :runtime\n    requirements = requirements.first if requirements.length == 1 # unpack\n\n    unless TYPES.include? type\n      raise ArgumentError, \"Valid types are #{TYPES.inspect}, \" \\\n                           \"not #{type.inspect}\"\n    end\n\n    @name        = name\n    @requirement = Gem::Requirement.create requirements\n    @type        = type\n    @prerelease  = false\n\n    # This is for Marshal backwards compatibility. See the comments in\n    # +requirement+ for the dirty details.","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/ruby/ruby/blob/0e5b888e1c355f3f728f2659f085820937dada48/lib/rubygems/dependency.rb#L26-L62","documentation":"Gem::Dependency.new validates its first argument: a String is required (a Regexp is still accepted with a deprecation warning). Anything else — Symbol, Gem::Version, Integer, nil — raises ArgumentError with the received value in the message.","triggerScenarios":"`Gem::Dependency.new(:rake, \">= 13\")`; spec.add_dependency called with a symbol variable; swapped argument order so a Gem::Version or nil lands in the name slot.","commonSituations":"Metaprogramming where names became symbols; helper APIs accepting strings-or-symbols and passing through; refactors from Bundler dependency objects; typos in name/version order.","solutions":["Convert before constructing: `Gem::Dependency.new(name.to_s, *reqs)`.","Check the `inspect` output in the message to see the actual object that arrived, then fix the call site (wrong variable or wrong order).","Coerce external input early: `name = String(name)` after validating it is String/Symbol."],"exampleFix":"# before\ndep = Gem::Dependency.new(:rake, \">= 13.0\")\n# after\ndep = Gem::Dependency.new(\"rake\", \">= 13.0\")","handlingStrategy":"type-guard","validationCode":"raise ArgumentError, \"dependency name must be a String\" unless name.is_a?(String)\ndep = Gem::Dependency.new(name, *reqs)","typeGuard":"def valid_dependency_name?(name)\n  name.is_a?(String)\nend","tryCatchPattern":null,"preventionTips":["Coerce symbols to strings at your API boundary before constructing dependencies.","Validate gemspec DSL input (names/requirements) early."],"tags":["rubygems","dependency","type-validation","argumenterror"],"backgroundTag":"type-validation-failed","analyzedSha":"0e5b888e1c355f3f728f2659f085820937dada48","analyzedAt":"2026-08-21T14:25:43.473Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}