puppetlabs/puppet · error · ArgumentError
Name must be a String not %{klass}
Error message
Name must be a String not %{klass} What it means
The package type's name parameter (a namevar) validates that it is a String: arrays, nil/undef, hashes, or symbols raise "Name must be a String not %{klass}". One package resource manages exactly one package name.
Source
Thrown at lib/puppet/type/package.rb:274
...
$ssh = $os['name'] ? {
solaris => SMCossh,
default => openssh
}
package { 'openssh':
ensure => installed,
name => $ssh,
require => Package['openssl'],
}
"
isnamevar
validate do |value|
unless value.is_a?(String)
raise ArgumentError, _("Name must be a String not %{klass}") % { klass: value.class }
end
end
end
# We call providify here so that we can set provider as a namevar.
# Normally this method is called after newtype finishes constructing this
# Type class.
providify
paramclass(:provider).isnamevar
def self.parameters_to_include
[:provider]
end
# Specify a targeted package management command.
newparam(:command, :required_features => :targetable) do
desc <<-EOT
The targeted command to use when managing a package:View on GitHub (pinned to e227c27540)
Solutions
- Set name to a single string: `name => 'openssl'`.
- For multiple packages iterate: `['a','b'].each |$p| { package { $p: ensure => installed } }`.
- Fix Hiera so the key resolves, and guard with `assert_type(String, $name)`.
- In Ruby, fail loudly on nil instead of coercing it to the string 'nil'.
Example fix
// before
package { 'ssh': name => ['openssh-server', 'openssh-client'] }
// after
['openssh-server', 'openssh-client'].each |$p| {
package { $p: ensure => installed }
} Defensive patterns
Strategy: type-guard
Validate before calling
// Puppet: guard Hiera-sourced names $name = assert_type(String, $name)
Type guard
def package_name_ok?(v) v.is_a?(String) && !v.empty? end
Prevention
- One name per resource; loop over lists instead.
- assert_type(String, ...) on any Hiera-sourced name.
- Watch refactors that leave the name key undef.
- Put arrays in the resource title, never in the name parameter.
When it happens
Trigger: `package { 'foo': name => ['a', 'b'] }`; a Hiera lookup where the name key resolves to undef; ENC or Ruby code passing a hash/symbol; note that array titles like `package { ['a','b']: }` are fine — only an explicit non-string name parameter raises.
Common situations: Hiera data missing the name key after refactors; external tools emitting lists into name; assuming array-title semantics apply to the name parameter; params classes defaulting name to undef.
Related errors
- value of %{opts} must be a hash
- puppet.tasks/unparseable-metadata
- Undefined variable '%{name}'; %{reason}
- Could not find data item %{key} in any Hiera data file and n
- Please supply a parameter to perform a Hiera lookup
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/491adf1ec7ce5c22.
Report an issue: GitHub.