{"record":{"id":"27e2e7430b0a0af5","repo":"puppetlabs/puppet","slug":"init-cannot-be-parameterized-with-an-undefined-typ","errorCode":null,"errorMessage":"Init cannot be parameterized with an undefined type and additional arguments","messagePattern":"Init cannot be parameterized with an undefined type and additional arguments","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_init_type.rb","lineNumber":26,"sourceCode":"    create_ptype(loader, ir, 'AnyType',\n                 'type' => {\n                   KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),\n                   KEY_VALUE => nil\n                 },\n                 'init_args' => {\n                   KEY_TYPE => PArrayType::DEFAULT,\n                   KEY_VALUE => EMPTY_ARRAY\n                 })\n  end\n\n  attr_reader :init_args\n\n  def initialize(type, init_args)\n    super(type)\n    @init_args = init_args.nil? ? EMPTY_ARRAY : init_args\n\n    if type.nil?\n      raise ArgumentError, _('Init cannot be parameterized with an undefined type and additional arguments') unless @init_args.empty?\n\n      @initialized = true\n    else\n      @initialized = false\n    end\n  end\n\n  def instance?(o, guard = nil)\n    really_instance?(o, guard) == 1\n  end\n\n  # @api private\n  def really_instance?(o, guard = nil)\n    if @type.nil?\n      TypeFactory.rich_data.really_instance?(o)\n    else\n      assert_initialized\n      guarded_recursion(guard, 0) do |g|","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_init_type.rb#L8-L44","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before\ntype = maybe_type          # may be nil\ninit = Puppet::Pops::Types::PInitType.new(type, args)\n\n# after\nraise ArgumentError, 'type required with init args' if type.nil? && !args.empty?\ninit = Puppet::Pops::Types::PInitType.new(type, args || Puppet::Pops::Types::EMPTY_ARRAY)","handlingStrategy":"validation","validationCode":"# Ruby — refuse meaningless construction early\nraise ArgumentError, 'PInitType needs a type when init args are given' if type.nil? && !args.nil? && !args.empty?\nPuppet::Pops::Types::PInitType.new(type, args)","typeGuard":"def init_args_valid?(type, args)\n  !type.nil? || args.nil? || args.empty?\nend","tryCatchPattern":"begin\n  Puppet::Pops::Types::PInitType.new(type, args)\nrescue ArgumentError => e\n  raise ArgumentError, \"bad Init construction (type=#{type.inspect}): #{e.message}\"\nend","preventionTips":["Centralize Init type construction in one helper that validates type and args together.","Never default the type parameter to nil when args are configurable."],"tags":["puppet","pcore","init-type","type-system","argument-validation"],"backgroundTag":"invalid-type-parameter","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}