puppetlabs/puppet · error · ArgumentError

Can only delete from an Array or Hash.

Error message

Can only delete from an Array or Hash.

What it means

Guard in EvaluatorImpl#delete (the - operator): deletion is only defined for Array and Hash left operands; something else was used as the container.

Solutions

  1. Apply - only to an Array or Hash
  2. Use other means (e.g. string manipulation) for non-container types
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at lib/puppet/pops/evaluator/evaluator_impl.rb:1275 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/7d18e9fb5841aa2c. Report an issue: GitHub.

Appendix: source

Thrown at lib/puppet/pops/evaluator/evaluator_impl.rb:1275

  def delete(x, y)
    result = x.dup
    case x
    when Array
      y = case y
          when Array then y
          when Hash  then y.to_a
          else            [y]
          end
      y.each { |e| result.delete(e) }
    when Hash
      y = case y
          when Array then y
          when Hash  then y.keys
          else            [y]
          end
      y.each { |e| result.delete(e) }
    else
      raise ArgumentError, _("Can only delete from an Array or Hash.")
    end
    result
  end

  # Implementation of case option matching.
  #
  # This is the type of matching performed in a case option, using == for every type
  # of value except regular expression where a match is performed.
  #
  def is_match?(left, right, o, option_expr, scope)
    @@compare_operator.match(left, right, scope)
  end

  # Maps the expression in the given array to their product except for UnfoldExpressions which are first unfolded.
  # The result is added to the given result Array.
  # @param result [Array] Where to add the result (may contain information to add to)
  # @param array [Array[Model::Expression] the expressions to map
  # @param scope [Puppet::Parser::Scope] the scope to evaluate in

View on GitHub (pinned to e227c27540)