puppetlabs/puppet · error · ArgumentError
Expected an Array or String, got a %{klass}
Error message
Expected an Array or String, got a %{klass} What it means
Puppet::Settings::ArraySetting#munge normalizes values for :type => :array settings: a String is split on /\s*,\s*/ into elements, an Array passes through, and any other class (Integer, Hash, true, Symbol...) raises ArgumentError. Munging happens when the value is converted on read, so the error surfaces at lookup time, not at assignment time.
Source
Thrown at lib/puppet/settings/array_setting.rb:15
# frozen_string_literal: true
class Puppet::Settings::ArraySetting < Puppet::Settings::BaseSetting
def type
:array
end
def munge(value)
case value
when String
value.split(/\s*,\s*/)
when Array
value
else
raise ArgumentError, _("Expected an Array or String, got a %{klass}") % { klass: value.class }
end
end
end
View on GitHub (pinned to e227c27540)
Solutions
- Pass a comma-separated String ('a,b,c') or a real Array (['a','b','c']) for array-typed settings.
- Fix the producer of the value (template/CLI wrapper) so it never emits Integer/boolean/Hash for these keys.
- If you control the setting, verify its declaration uses :type => :array and all callers honor that.
Example fix
# before Puppet.settings[:mylist] = 5 # after Puppet.settings[:mylist] = 'a,b,c' # or Puppet.settings[:mylist] = %w[a b c]
Defensive patterns
Strategy: type-guard
Validate before calling
unless value.is_a?(String) || value.is_a?(Array)
raise ArgumentError, "array setting expects String or Array, got #{value.class}"
end
Puppet.settings[:mylist] = value Type guard
array_setting_input = ->(v) { v.is_a?(String) || v.is_a?(Array) } Try / catch
begin
Puppet.settings[:mylist] = value
rescue ArgumentError => e
raise unless e.message.include?('Expected an Array or String')
Puppet.settings[:mylist] = Array(value) # or value.to_s
end Prevention
- Emit comma-separated strings or real arrays from config templates for list settings
- Never let integers/booleans/objects reach array-typed settings
- Type-check generated config values in your provisioning code before applying
When it happens
Trigger: Setting an array-typed setting to an integer or boolean from code (Puppet.settings[:mylist] = 5); YAML-sourced config producing a Hash where a list was expected; CLI override `--mylist 5` parsed to an Integer before munging.
Common situations: Automated config generation (Hiera-backed templates) writing scalars into list settings; environment differences where one host passes a string 'a,b' and another passes JSON-parsed numbers; refactors changing a value's type.
Related errors
- Invalid value '%{value}' for boolean parameter: %{name}
- Illegal format '#{actual}' specified for value of Array type
- #{subject} #{what},
- key is a %{klass}, not a string or symbol
- Invalid instance type %{klass}, expected %{model_type}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/1b5e7438cdd561c5.
Report an issue: GitHub.