puppetlabs/puppet · error · ArgumentError
Init cannot be parameterized with an undefined type and addi
Error message
Init cannot be parameterized with an undefined type and additional arguments
What it means
PInitType#initialize rejects constructing an Init type with no target type while init arguments are supplied — with a nil type there is nothing to construct, so extra arguments are meaningless. The bare Ruby-level ArgumentError signals programmatic misuse; Puppet DSL parsing does not normally produce this shape.
Source
Thrown at lib/puppet/pops/types/p_init_type.rb:26
create_ptype(loader, ir, 'AnyType',
'type' => {
KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
KEY_VALUE => nil
},
'init_args' => {
KEY_TYPE => PArrayType::DEFAULT,
KEY_VALUE => EMPTY_ARRAY
})
end
attr_reader :init_args
def initialize(type, init_args)
super(type)
@init_args = init_args.nil? ? EMPTY_ARRAY : init_args
if type.nil?
raise ArgumentError, _('Init cannot be parameterized with an undefined type and additional arguments') unless @init_args.empty?
@initialized = true
else
@initialized = false
end
end
def instance?(o, guard = nil)
really_instance?(o, guard) == 1
end
# @api private
def really_instance?(o, guard = nil)
if @type.nil?
TypeFactory.rich_data.really_instance?(o)
else
assert_initialized
guarded_recursion(guard, 0) do |g|View on GitHub (pinned to e227c27540)
Solutions
- Pass a concrete target type: PInitType.new(PStringType::DEFAULT, args).
- When the type legitimately is nil, pass an empty args array: PInitType.new(nil, Puppet::Pops::Types::EMPTY_ARRAY).
- Guard the construction site: raise a clear error of your own if type.nil? && !args.empty? before calling PInitType.new.
Example fix
# before type = maybe_type # may be nil init = Puppet::Pops::Types::PInitType.new(type, args) # after raise ArgumentError, 'type required with init args' if type.nil? && !args.empty? init = Puppet::Pops::Types::PInitType.new(type, args || Puppet::Pops::Types::EMPTY_ARRAY)
Defensive patterns
Strategy: validation
Validate before calling
# Ruby — refuse meaningless construction early raise ArgumentError, 'PInitType needs a type when init args are given' if type.nil? && !args.nil? && !args.empty? Puppet::Pops::Types::PInitType.new(type, args)
Type guard
def init_args_valid?(type, args) !type.nil? || args.nil? || args.empty? end
Try / catch
begin
Puppet::Pops::Types::PInitType.new(type, args)
rescue ArgumentError => e
raise ArgumentError, "bad Init construction (type=#{type.inspect}): #{e.message}"
end Prevention
- Centralize Init type construction in one helper that validates type and args together.
- Never default the type parameter to nil when args are configurable.
When it happens
Trigger: Ruby API: Puppet::Pops::Types::PInitType.new(nil, [1, 2]) or TypeFactory code that passes a conditionally-nil type together with a non-empty args array (e.g. type = cond ? PStringType::DEFAULT : nil).
Common situations: Type-building helper methods where the type argument comes from a lookup or config that can return nil; refactors that pass a defaulted args array while forgetting the type default.
Related errors
- Creation of new instance of type '%{type_name}' is not suppo
- The type '%{type}' does not represent a valid set of paramet
- Only Runtime type 'ruby' is supported, got #{type.runtime}
- #{my_caller.class}(): wrong argument type (#{obj.class}; is
- 'from' must be less or equal to 'to'. Got (#{from}, #{to}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/27e2e7430b0a0af5.
Report an issue: GitHub.