puppetlabs/puppet · error · Puppet::Error

Got nil value for #{name}

Error message

Got nil value for #{name}

What it means

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.

Source

Thrown at lib/puppet/type.rb:683

      nil
    end
  end

  # Sets the 'should' (wanted state) value of a property, or the value of a parameter.
  #
  # @raise [Puppet::Error] if the setting of the value fails, or if the given name is nil.
  # @raise [Puppet::ResourceError] when the parameter validation raises Puppet::Error or
  #   ArgumentError
  def []=(name, value)
    name = name.intern

    fail("no parameter named '#{name}'") unless self.class.validattr?(name)

    if name == :name
      nv = name_var
      name = nv if nv
    end
    raise Puppet::Error, "Got nil value for #{name}" if value.nil?

    property = newattr(name)

    if property
      begin
        # make sure the parameter doesn't have any errors
        property.value = value
      rescue Puppet::Error, ArgumentError => detail
        error = Puppet::ResourceError.new(_("Parameter %{name} failed on %{ref}: %{detail}") %
                                              { name: name, ref: ref, detail: detail })
        adderrorcontext(error, detail)
        raise error
      end
    end
  end

  # Removes an attribute from the object; useful in testing or in cleanup
  # when an error has been encountered

View on GitHub (pinned to e227c27540)

Solutions

  1. Give the variable a real default in the manifest: $svc_user = pick($svc_user, 'root') or lookup with a default
  2. Guard the attribute: only set the parameter when the variable is defined (if $svc_user { ... } around the resource or use a wrapper)
  3. Use the puppet4 undef-safe patterns: selector $svc_user ? { undef => 'root', default => $svc_user }
  4. Audit with puppet lookup --node <n> <key> to confirm which nodes lack the data

Example fix

# before
file { '/srv/app': ensure => directory, owner => $svc_user } # $svc_user may be undef

# after
$svc_user = pick(lookup('app::service_user', { 'default_value' => undef }), 'root')
file { '/srv/app': ensure => directory, owner => $svc_user }
Defensive patterns

Strategy: validation

Validate before calling

value = :root if value.nil? # or skip the parameter
resource[:owner] = value unless value.nil?

Try / catch

begin
  resource[param] = value
rescue Puppet::Error => e
  raise unless e.message =~ /Got nil value/
  # treat as unmanaged
end

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/7036a9ea6b8b2fe2. Report an issue: GitHub.