puppetlabs/puppet · error · Puppet::ParseError
'%{pn}' is not a known type parameter for %{label}-Type
Error message
'%{pn}' is not a known type parameter for %{label}-Type What it means
When an Object type is parameterized with a single Hash argument that is not itself assignable to the first type parameter, the hash is treated as named arguments: each key must be a declared type parameter name of the base type. An unknown key raises Puppet::ParseError naming the key and the type.
Source
Thrown at lib/puppet/pops/types/p_object_type_extension.rb:71
def initialize(base_type, init_parameters)
pts = base_type.type_parameters(true)
raise Puppet::ParseError, _('The %{label}-Type cannot be parameterized using []') % { label: base_type.label } if pts.empty?
@base_type = base_type
named_args = init_parameters.size == 1 && init_parameters[0].is_a?(Hash)
if named_args
# Catch case when first parameter is an assignable Hash
named_args = pts.size >= 1 && !pts.values[0].type.instance?(init_parameters[0])
end
by_name = {}
if named_args
hash = init_parameters[0]
hash.each_pair do |pn, pv|
tp = pts[pn]
if tp.nil?
raise Puppet::ParseError, _("'%{pn}' is not a known type parameter for %{label}-Type") % { pn: pn, label: base_type.label }
end
by_name[pn] = check_param(tp, pv) unless pv == :default
end
else
pts.values.each_with_index do |tp, idx|
if idx < init_parameters.size
pv = init_parameters[idx]
by_name[tp.name] = check_param(tp, pv) unless pv == :default
end
end
end
if by_name.empty?
raise Puppet::ParseError, _('The %{label}-Type cannot be parameterized using an empty parameter list') % { label: base_type.label }
end
@parameters = by_name
endView on GitHub (pinned to e227c27540)
Solutions
- Use exactly the declared type parameter names as hash keys: MyApp::Color[{channel => 3}]
- If the name is right but undefined, declare it under type_parameters in the Object definition
- Remember each value is type-checked against the parameter's declared type (check_param), so also verify the value kind
Example fix
# before
type MyApp::Color = Object[{ type_parameters => { channel => Integer } }]
$bad = MyApp::Color[{colour => 3}] # 'colour' is not a type parameter
# after
$good = MyApp::Color[{channel => 3}] Defensive patterns
Strategy: validation
Validate before calling
# named-argument keys must all be declared type parameter names
known = base_type.type_parameters(true).keys
unknown = arg_hash.keys - known
raise "unknown type parameters: #{unknown.inspect}; known: #{known.inspect}" unless unknown.empty? Type guard
def valid_type_param_keys?(base_type, hash) (hash.keys - base_type.type_parameters(true).keys).empty? end
Try / catch
begin Puppet::Pops::Types::PObjectTypeExtension.create(base_type, [hash]) rescue Puppet::ParseError => e raise unless e.message =~ /is not a known type parameter/ raise # e.message names the bad key and the type end
Prevention
- Copy type parameter names verbatim from the type definition
- When renaming a type parameter, grep call sites for the old name
When it happens
Trigger: MyApp::Color[{colour => 3}] when the declared type parameter is channel; also triggered by hash keys matching only an attribute name instead of a type parameter name. Note that a hash assignable to the first type parameter's type is instead bound positionally as that parameter's value.
Common situations: Typos or spelling differences (colour vs channel, UK/US variants); using attribute names in the parameterization hash; renaming a type parameter without updating call sites.
Related errors
- The %{label}-Type cannot be parameterized using []
- The %{label}-Type cannot be parameterized using an empty par
- The attribute '%{name}' is reserved and cannot be used
- Initializer for class #{impl_class.name} does not match the
- Initializer for class #{impl_class.name} parameter '#{ip}' d
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/6e5b2e50a30c8e0c.
Report an issue: GitHub.