{"record":{"id":"610256a9a10e5d73","repo":"puppetlabs/puppet","slug":"initializer-for-class-impl-class-name-parameter","errorCode":null,"errorMessage":"Initializer for class #{impl_class.name} parameter '#{ip}' does not match any of the attributes of type #{name}","messagePattern":"Initializer for class #(.+?) parameter '#(.+?)' does not match any of the attributes of type #(.+?)","errorType":"exception","errorClass":"Serialization::SerializationError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_object_type.rb","lineNumber":658,"sourceCode":"        # assert that the protected name wasn't a real name (names can start with underscore)\n        n = r unless param_names.index(r).nil?\n      end\n      n\n    end\n\n    if init_param_names != param_names\n      if init_param_names.size < param_count || init_non_opt_count > param_count\n        raise Serialization::SerializationError, \"Initializer for class #{impl_class.name} does not match the attributes of #{name}\"\n      end\n\n      init_param_names = init_param_names[0, param_count] if init_param_names.size > param_count\n      unless init_param_names == param_names\n        # Reorder needed to match initialize method arguments\n        new_param_types = []\n        init_param_names.each do |ip|\n          index = param_names.index(ip)\n          if index.nil?\n            raise Serialization::SerializationError,\n                  \"Initializer for class #{impl_class.name} parameter '#{ip}' does not match any of the attributes of type #{name}\"\n          end\n          new_param_types << param_types[index]\n        end\n        param_names = init_param_names\n        param_types = new_param_types\n      end\n    end\n\n    pic = [param_names.freeze, param_types.freeze, non_opt_types.size].freeze\n    @parameter_info[impl_class] = pic\n    pic\n  end\n\n  # @api private\n  def attr_reader_name(se)\n    if se.value_type.is_a?(PBooleanType) || se.value_type.is_a?(POptionalType) && se.value_type.type.is_a?(PBooleanType)\n      \"#{se.name}?\"","sourceCodeStart":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_object_type.rb#L640-L676","documentation":"Companion to the initializer arity check in parameter_info: when the Ruby implementation class's initialize parameter list is the right size but a parameter name matches none of the Object type's attributes, Puppet cannot map constructor arguments to attributes and raises Serialization::SerializationError naming the offending parameter.","triggerScenarios":"initialize has a parameter whose name is not an attribute of the type: a typo (w vs z), a renamed attribute still referenced by the old name in initialize, or an extra positional parameter with a default value that shadows no attribute.","commonSituations":"Renaming an attribute in the interface string while leaving the implementation class unchanged; hand-written implementation classes whose initialize uses different names than the declarative attributes; copy-paste between similar types.","solutions":["Rename the initialize parameter to exactly match the declared attribute name","If the name is correct in initialize, add or fix the attribute in the interface so the two agree","Remove the stray parameter entirely if it corresponds to no attribute"],"exampleFix":"# before\ntype attributes: { x => Integer, y => Integer, z => Integer }\ndef initialize(x, y, w)      # 'w' matches no attribute\n  ...\nend\n\n# after\ndef initialize(x, y, z)\n  ...\nend","handlingStrategy":"validation","validationCode":"# assert every initialize parameter name is an attribute name\nattr_names = type.attributes(true).keys\nparams = impl_class.instance_method(:initialize).parameters.map { |_, n| n.to_s }\nunknown = params - attr_names\nabort \"initialize parameters not matching any attribute: #{unknown.inspect}\" unless unknown.empty?","typeGuard":null,"tryCatchPattern":"begin\n  type.create(*args)\nrescue Puppet::Pops::Serialization::SerializationError => e\n  raise unless e.message =~ /parameter '.*' does not match any of the attributes/\n  # e.message names the offending parameter; fix the impl class signature\n  raise\nend","preventionTips":["Name initialize parameters exactly after the declared attributes","Run a startup assertion comparing parameter names with attribute names (see validationCode)","Rename attributes and initialize parameters together in one refactor"],"tags":["puppet","pcore","serialization","object-type","ruby"],"backgroundTag":"constructor-signature-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}