{"record":{"id":"7036a9ea6b8b2fe2","repo":"puppetlabs/puppet","slug":"got-nil-value-for-name","errorCode":null,"errorMessage":"Got nil value for #{name}","messagePattern":"Got nil value for #(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/type.rb","lineNumber":683,"sourceCode":"      nil\n    end\n  end\n\n  # Sets the 'should' (wanted state) value of a property, or the value of a parameter.\n  #\n  # @raise [Puppet::Error] if the setting of the value fails, or if the given name is nil.\n  # @raise [Puppet::ResourceError] when the parameter validation raises Puppet::Error or\n  #   ArgumentError\n  def []=(name, value)\n    name = name.intern\n\n    fail(\"no parameter named '#{name}'\") unless self.class.validattr?(name)\n\n    if name == :name\n      nv = name_var\n      name = nv if nv\n    end\n    raise Puppet::Error, \"Got nil value for #{name}\" if value.nil?\n\n    property = newattr(name)\n\n    if property\n      begin\n        # make sure the parameter doesn't have any errors\n        property.value = value\n      rescue Puppet::Error, ArgumentError => detail\n        error = Puppet::ResourceError.new(_(\"Parameter %{name} failed on %{ref}: %{detail}\") %\n                                              { name: name, ref: ref, detail: detail })\n        adderrorcontext(error, detail)\n        raise error\n      end\n    end\n  end\n\n  # Removes an attribute from the object; useful in testing or in cleanup\n  # when an error has been encountered","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/type.rb#L665-L701","documentation":"Puppet::Type#[]= (lib/puppet/type.rb) assigns parameter values on a resource instance and treats nil as 'unmanaged' internally, so it explicitly rejects nil with Puppet::Error 'Got nil value for <param>'. The check happens after name validation and before the property/parameter object is created, so nothing is partially applied.","triggerScenarios":"Ruby-side: resource[:owner] = nil. Manifest-side: a parameter assigned an undefined variable ('owner => $svc_user' where $svc_user is undef) or a hiera lookup returning nothing (lookup('key') without default). Also conditional params built by code that yields nil branches.","commonSituations":"Hiera key missing for one node while present for others; optional variables that default to undef; refactors renaming a variable so the referenced one is now undef; data lookups moving to a different backend where the key was not migrated.","solutions":["Give the variable a real default in the manifest: $svc_user = pick($svc_user, 'root') or lookup with a default","Guard the attribute: only set the parameter when the variable is defined (if $svc_user { ... } around the resource or use a wrapper)","Use the puppet4 undef-safe patterns: selector $svc_user ? { undef => 'root', default => $svc_user }","Audit with puppet lookup --node <n> <key> to confirm which nodes lack the data"],"exampleFix":"# before\nfile { '/srv/app': ensure => directory, owner => $svc_user } # $svc_user may be undef\n\n# after\n$svc_user = pick(lookup('app::service_user', { 'default_value' => undef }), 'root')\nfile { '/srv/app': ensure => directory, owner => $svc_user }","handlingStrategy":"validation","validationCode":"value = :root if value.nil? # or skip the parameter\nresource[:owner] = value unless value.nil?","typeGuard":null,"tryCatchPattern":"begin\n  resource[param] = value\nrescue Puppet::Error => e\n  raise unless e.message =~ /Got nil value/\n  # treat as unmanaged\nend","preventionTips":["Use pick()/lookup defaults so variables passed as attributes are never undef","Wrap optional attributes in if $var { ... } blocks","Lint manifests for direct variable interpolation into attributes without defaults"],"tags":["puppet","nil-value","undef","resource-parameter","hiera"],"backgroundTag":"nil-value-assignment","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}