{"record":{"id":"8479157baa36e7dc","repo":"puppetlabs/puppet","slug":"the-name-property-must-be-specified-as-a-hash-o","errorCode":null,"errorMessage":"The %{name} property must be specified as a hash or an array of key/value pairs (strings)!","messagePattern":"The %(.+?) property must be specified as a hash or an array of key/value pairs \\(strings\\)!","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/property/keyvalue.rb","lineNumber":133,"sourceCode":"          :absent\n        end\n      end\n\n      # Returns true if there is no _is_ value, else returns if _is_ is equal to _should_ using == as comparison.\n      # @return [Boolean] whether the property is in sync or not.\n      def insync?(is)\n        return true unless is\n\n        (is == should)\n      end\n\n      # We only accept an array of key/value pairs (strings), a single\n      # key/value pair (string) or a Hash as valid values for our property.\n      # Note that for an array property value, the 'value' passed into the\n      # block corresponds to the array element.\n      validate do |value|\n        unless value.is_a?(String) || value.is_a?(Hash)\n          raise ArgumentError, _(\"The %{name} property must be specified as a hash or an array of key/value pairs (strings)!\") % { name: name }\n        end\n\n        next if value.is_a?(Hash)\n\n        unless value.include?(separator.to_s)\n          raise ArgumentError, _(\"Key/value pairs must be separated by '%{separator}'\") % { separator: separator }\n        end\n      end\n\n      # The validate step ensures that our passed-in value is\n      # either a String or a Hash. If our value's a string,\n      # then nothing else needs to be done. Otherwise, we need\n      # to stringify the hash's keys and values to match our\n      # internal representation of the property's value.\n      munge do |value|\n        next value if value.is_a?(String)\n\n        munged_value = value.to_a.map! do |hash_key, hash_value|","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/property/keyvalue.rb#L115-L151","documentation":"Puppet::Property::KeyValue is a base class for properties holding key/value settings (strings like 'k=v' or a Hash). Its validate block accepts only a String or a Hash; any other object - Integer, Array of non-strings, nil - raises ArgumentError demanding 'a hash or an array of key/value pairs (strings)'. Puppet casts should-values to arrays, so the block runs per element: one bad element fails the whole property value.","triggerScenarios":"Setting a KeyValue-derived property to a number (attrs => 42), an array of numbers, or undef; passing nested structures where flat 'k=v' strings or a single Hash were expected.","commonSituations":"Hiera data storing numbers without quotes (or over-quoted strings); users assuming structured input; modules whose documentation is unclear about the accepted shape.","solutions":["Pass strings formatted as key<separator>value: attrs => 'answer=42'.","Pass a single Hash when the property supports it: attrs => { 'answer' => '42' }.","Validate and coerce the parameter before it reaches the resource."],"exampleFix":"# before (Puppet DSL)\nmytype { 'x': attrs => 42 }            # ArgumentError\n\n# after\nmytype { 'x': attrs => 'answer=42' }   # or attrs => { 'answer' => '42' }","handlingStrategy":"validation","validationCode":"# Ruby\nok = value.is_a?(String) || value.is_a?(Hash)\n\n# Puppet DSL: constrain the parameter\nVariant[String, Hash] $attrs = {}","typeGuard":"def keyvalue_shaped?(v)\n  v.is_a?(String) || v.is_a?(Hash)\nend","tryCatchPattern":null,"preventionTips":["Type module parameters as Variant[String, Hash] (or an Array of them) so bad shapes fail at compile time.","Keep numeric values inside the pair string ('answer=42'), not as bare numbers.","Remember validation runs per element for array values - check every element."],"tags":["puppet","property","keyvalue","validation","puppet-dsl"],"backgroundTag":"invalid-key-value-format","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}