{"record":{"id":"1b5e7438cdd561c5","repo":"puppetlabs/puppet","slug":"expected-an-array-or-string-got-a-klass","errorCode":null,"errorMessage":"Expected an Array or String, got a %{klass}","messagePattern":"Expected an Array or String, got a %(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/settings/array_setting.rb","lineNumber":15,"sourceCode":"# frozen_string_literal: true\n\nclass Puppet::Settings::ArraySetting < Puppet::Settings::BaseSetting\n  def type\n    :array\n  end\n\n  def munge(value)\n    case value\n    when String\n      value.split(/\\s*,\\s*/)\n    when Array\n      value\n    else\n      raise ArgumentError, _(\"Expected an Array or String, got a %{klass}\") % { klass: value.class }\n    end\n  end\nend\n","sourceCodeStart":1,"sourceCodeEnd":19,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/settings/array_setting.rb#L1-L19","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nPuppet.settings[:mylist] = 5\n\n# after\nPuppet.settings[:mylist] = 'a,b,c'\n# or\nPuppet.settings[:mylist] = %w[a b c]","handlingStrategy":"type-guard","validationCode":"unless value.is_a?(String) || value.is_a?(Array)\n  raise ArgumentError, \"array setting expects String or Array, got #{value.class}\"\nend\nPuppet.settings[:mylist] = value","typeGuard":"array_setting_input = ->(v) { v.is_a?(String) || v.is_a?(Array) }","tryCatchPattern":"begin\n  Puppet.settings[:mylist] = value\nrescue ArgumentError => e\n  raise unless e.message.include?('Expected an Array or String')\n  Puppet.settings[:mylist] = Array(value) # or value.to_s\nend","preventionTips":["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"],"tags":["puppet","settings","array","type-mismatch","munge"],"backgroundTag":"config-value-type-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}