{"record":{"id":"6ce03b866619311a","repo":"puppetlabs/puppet","slug":"can-only-append-array-or-hash-to-a-hash","errorCode":null,"errorMessage":"Can only append Array or Hash to a Hash","messagePattern":"Can only append Array or Hash to a Hash","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/evaluator/evaluator_impl.rb","lineNumber":1235,"sourceCode":"      x + y # new array with concatenation\n    when Hash\n      y = case y\n          when Hash then y\n          when Array\n            # Hash[[a, 1, b, 2]] => {}\n            # Hash[a,1,b,2] => {a => 1, b => 2}\n            # Hash[[a,1], [b,2]] => {[a,1] => [b,2]}\n            # Hash[[[a,1], [b,2]]] => {a => 1, b => 2}\n            # Use type calculator to determine if array is Array[Array[?]], and if so use second form\n            # of call\n            t = @@type_calculator.infer(y)\n            if t.element_type.is_a? Types::PArrayType\n              y.to_h\n            else\n              Hash[*y]\n            end\n          else\n            raise ArgumentError, _('Can only append Array or Hash to a Hash')\n          end\n      x.merge y # new hash with overwrite\n    when URI\n      raise ArgumentError, _('An URI can only be merged with an URI or String') unless y.is_a?(String) || y.is_a?(URI)\n\n      x + y\n    when Types::PBinaryType::Binary\n      raise ArgumentError, _('Can only append Binary to a Binary') unless y.is_a?(Types::PBinaryType::Binary)\n\n      Types::PBinaryType::Binary.from_binary_string(x.binary_buffer + y.binary_buffer)\n    else\n      concatenate([x], y)\n    end\n  end\n\n  # Produces the result x \\ y (set difference)\n  # When `x` is an Array, `y` is transformed to an array and then all matching elements removed from x.\n  # When `x` is a Hash, all contained keys are removed from x as listed in `y` if it is an Array, or all its keys if it is a Hash.","sourceCodeStart":1217,"sourceCodeEnd":1253,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/evaluator/evaluator_impl.rb#L1217-L1253","documentation":"Error \"Can only append Array or Hash to a Hash\" thrown in puppetlabs/puppet.","triggerScenarios":"Thrown at lib/puppet/pops/evaluator/evaluator_impl.rb:1235 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}