{"record":{"id":"79b53eee25c70899","repo":"puppetlabs/puppet","slug":"unable-to-create-an-instance-of-name-class-n","errorCode":null,"errorMessage":"Unable to create an instance of #{name}. #{class_name} does not include module #{PuppetObject.name}","messagePattern":"Unable to create an instance of #(.+?)\\. #(.+?) does not include module #(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_object_type.rb","lineNumber":565,"sourceCode":"    end\n  end\n\n  # @api private\n  def implementation_class(create = true)\n    if @implementation_class.nil? && create\n      ir = Loaders.implementation_registry\n      class_name = ir.nil? ? nil : ir.module_name_for_type(self)\n      if class_name.nil?\n        # Use generator to create a default implementation\n        @implementation_class = RubyGenerator.new.create_class(self)\n        @implementation_class.class_eval(&@implementation_override) if instance_variable_defined?(:@implementation_override)\n      else\n        # Can the mapping be loaded?\n        @implementation_class = ClassLoader.provide(class_name)\n\n        raise Puppet::Error, \"Unable to load class #{class_name}\" if @implementation_class.nil?\n        unless @implementation_class < PuppetObject || @implementation_class.respond_to?(:ecore)\n          raise Puppet::Error, \"Unable to create an instance of #{name}. #{class_name} does not include module #{PuppetObject.name}\"\n        end\n      end\n    end\n    @implementation_class\n  end\n\n  # @api private\n  def implementation_class=(cls)\n    raise ArgumentError, \"attempt to redefine implementation class for #{label}\" unless @implementation_class.nil?\n\n    @implementation_class = cls\n  end\n\n  # The block passed to this method will be passed in a call to `#class_eval` on the dynamically generated\n  # class for this data type. It's indended use is to complement or redefine the generated methods and\n  # attribute readers.\n  #\n  # The method is normally called with the block passed to `#implementation` when a data type is defined using","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_object_type.rb#L547-L583","documentation":"A loaded implementation class for an Object type must either include Puppet::Pops::Types::PuppetObject (so instances support _pcore_type and PCore construction) or be an RGen metamodel class (responds to :ecore). If ClassLoader returns a class satisfying neither, Puppet::Error explains that the class does not include the PuppetObject module.","triggerScenarios":"The registry mapping resolves to an existing Ruby class that is not a Puppet object implementation — e.g. a name collision where the mapped name resolves to a helper/stdlib class (::Set, ::Logger, a module of your own), or a hand-written implementation class created without including PuppetObject.","commonSituations":"Mapping a data type to an arbitrary domain class expecting Puppet to adapt it automatically; constant resolution picking up an unexpected toplevel constant of the same name; upgrading code where the implementation was replaced by a plain class.","solutions":["In your implementation class, include Puppet::Pops::Types::PuppetObject (implementing _pcore_type / the standard constructor pattern, easiest via Puppet::DataTypes.create_type with an implementation block).","If the class is an RGen/Ecore model class, respond to :ecore — that path is also accepted.","Check the mapped name for collisions: ensure the registry entry points at the class you think it does (confirm with ClassLoader.provide in a Ruby shell)."],"exampleFix":"# before\nclass PuppetX::Mymod::Widget\n  attr_reader :size\nend\n\n# after\nrequire 'puppet/pops/types/puppet_object'\nclass PuppetX::Mymod::Widget\n  include Puppet::Pops::Types::PuppetObject\n  attr_reader :size\nend","handlingStrategy":"type-guard","validationCode":"# Ruby — verify the contract after loading the mapped class\nklass = Puppet::Pops::Types::ClassLoader.provide(class_name)\nunless klass.nil? || (klass < Puppet::Pops::Types::PuppetObject || klass.respond_to?(:ecore))\n  fail(\"#{class_name} must include PuppetObject or be an RGen (ecore) class\")\nend","typeGuard":"def puppet_object_class?(klass)\n  klass < Puppet::Pops::Types::PuppetObject || klass.respond_to?(:ecore)\nend","tryCatchPattern":"begin\n  obj_type.implementation_class\nrescue Puppet::Error => e\n  raise TypeError, \"#{e.message} — include Puppet::Pops::Types::PuppetObject in the mapped class\"\nend","preventionTips":["Base hand-written implementations on Puppet::DataTypes.create_type so the boilerplate is generated.","Avoid mapping types to generic/toplevel constants; namespace implementation classes uniquely."],"tags":["puppet","object-type","implementation-class","interface-implementation","puppet-object"],"backgroundTag":"implementation-class-interface-missing","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}