puppetlabs/puppet · error · ArgumentError
Cannot transform object of class %{klass}
Error message
Cannot transform object of class %{klass} What it means
Raised by CollectorTransformer#query_Object, the fallback handler for a collector search expression whose node class has no dedicated query_ translator. Collector queries (<| ... |>) support only a small grammar — comparisons (==/!=/and/or/not), tag checks, parenthesized expressions, and qualified names; anything else (function calls, arithmetic, literal structures) reaches query_Object and is rejected with the offending class name.
Source
Thrown at lib/puppet/pops/evaluator/collector_transformer.rb:171
def query_LiteralNumber(o, scope)
@@evaluator.evaluate(o, scope)
end
def query_LiteralUndef(o, scope)
nil
end
def query_QualifiedName(o, scope)
@@evaluator.evaluate(o, scope)
end
def query_ParenthesizedExpression(o, scope)
query(o.expr, scope)
end
def query_Object(o, scope)
raise ArgumentError, _("Cannot transform object of class %{klass}") % { klass: o.class }
end
def match_AccessExpression(o, scope)
pops_object = @@evaluator.evaluate(o, scope)
# Convert to Puppet 3 style objects since that is how they are represented
# in the catalog.
@@evaluator.convert(pops_object, scope, nil)
end
def match_AndExpression(o, scope)
left_match = match(o.left_expr, scope)
right_match = match(o.right_expr, scope)
[left_match, 'and', right_match]
end
def match_OrExpression(o, scope)
left_match = match(o.left_expr, scope)View on GitHub (pinned to e227c27540)
Solutions
- Precompute values into variables and compare against them: `$wanted = regsubst('a','b','c')` then `<| title == $wanted |>`.
- Restructure the query to use only supported operators: ==, !=, and, or, not, and `tag` comparisons.
- For logic too complex for collectors, collect broadly and filter in a loop over the collected resources instead.
Example fix
# before
File<| title == regsubst('base','prod','stage') |> # Cannot transform object of class Puppet::Pops::Model::CallExpression
# after
$wanted = regsubst('base','prod','stage')
File<| title == $wanted |> Defensive patterns
Strategy: validation
Validate before calling
# Precompute every dynamic operand, then keep the query grammar pure:
$wanted = regsubst('base','prod','stage')
File<| title == $wanted |> Prevention
- Restrict collector queries to ==, !=, and, or, not and tag comparisons.
- Hoist function calls/arithmetic into variables outside the <| ... |> brackets.
- For complex predicates, collect broadly and filter in normal Puppet code afterwards.
When it happens
Trigger: `<| title == regsubst('a','b','c') |>`, `<| (foo + 1) == 3 |>`, `<| defined(File) |>` — any CallExpression, ArithmeticExpression, or other unsupported node occupying a query-grammar position inside `<| ... |>` or `Type<| ... |>`.
Common situations: Trying to make collection searches 'dynamic' by calling functions or computing values inline; porting complex SQL-like filters into collectors; assuming general Puppet expressions are valid inside collector brackets.
Related errors
- Cannot transform a number to a tag
- Function Load Error for function '%{function_name}': %{messa
- A required parameter cannot be added after an optional param
- block_param accepts max 2 arguments (type, name), got %{size
- Attempt to redefine block
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/ec85f72dbb113256.
Report an issue: GitHub.