puppetlabs/puppet · error · ArgumentError
The code loaded from %{source_ref} does not create the resou
Error message
The code loaded from %{source_ref} does not create the resource type '%{type_name}' - no call to %{rname}.new found. What it means
Raised by PuppetResourceTypeImplInstantiator when the file has statements but none is a call to Resource::ResourceTypeImpl.new. The loader statically matches a CallMethodExpression whose functor is the QualifiedReference named by `Resource::ResourceTypeImpl._pcore_type.name` with selector 'new'; any other content (class bodies, function definitions, plain expressions) fails here.
Source
Thrown at lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb:51
statements = statements.reject { |s| s.is_a?(Model::Nop) }
if statements.empty?
raise ArgumentError, _("The code loaded from %{source_ref} does not create the resource type '%{type_name}' - it is empty") % { source_ref: source_ref, type_name: typed_name.name }
end
rname = Resource::ResourceTypeImpl._pcore_type.name
unless statements.find do |s|
if s.is_a?(Model::CallMethodExpression)
functor_expr = s.functor_expr
functor_expr.is_a?(Model::NamedAccessExpression) &&
functor_expr.left_expr.is_a?(Model::QualifiedReference) &&
functor_expr.left_expr.cased_value == rname &&
functor_expr.right_expr.is_a?(Model::QualifiedName) &&
functor_expr.right_expr.value == 'new'
else
false
end
end
raise ArgumentError, _("The code loaded from %{source_ref} does not create the resource type '%{type_name}' - no call to %{rname}.new found.") % { source_ref: source_ref, type_name: typed_name.name, rname: rname }
end
unless statements.size == 1
raise ArgumentError, _("The code loaded from %{source_ref} must contain only the creation of resource type '%{type_name}' - it has additional logic.") % { source_ref: source_ref, type_name: typed_name.name }
end
closure_scope = Puppet.lookup(:global_scope) { {} }
resource_type_impl = parser.evaluate(closure_scope, model)
unless resource_type_impl.is_a?(Puppet::Pops::Resource::ResourceTypeImpl)
got = resource_type.class
raise ArgumentError, _("The code loaded from %{source_ref} does not define the resource type '%{type_name}' - got '%{got}'.") % { source_ref: source_ref, type_name: typed_name.name, got: got }
end
unless resource_type_impl.name == typed_name.name
expected = typed_name.name
actual = resource_type_impl.name
raise ArgumentError, _("The code loaded from %{source_ref} produced resource type with the wrong name, expected '%{expected}', actual '%{actual}'") % { source_ref: source_ref, expected: expected, actual: actual }View on GitHub (pinned to e227c27540)
Solutions
- Replace the file content with a single Resource::ResourceTypeImpl.new('<module>::<name>', ...) call
- If you meant a data type alias, use the alias syntax in the module's type-alias location supported by your Puppet version
- Follow the Puppet resource-type-in-language docs for the exact constructor shape
Example fix
# before - resource type file containing a class
class mymod::greeting {
notify { 'hello': }
}
# after
Resource::ResourceTypeImpl.new('mymod::greeting',
is_capability: false,
attributes: {
message: { type: String, default: 'hello', kind: 'parameter' }
}
) Defensive patterns
Strategy: validation
Validate before calling
rname = Puppet::Pops::Resource::ResourceTypeImpl._pcore_type.name
has_ctor = statements.any? do |s|
next false unless s.is_a?(Puppet::Pops::Model::CallMethodExpression)
f = s.functor_expr
f.is_a?(Puppet::Pops::Model::NamedAccessExpression) &&
f.left_expr.is_a?(Puppet::Pops::Model::QualifiedReference) &&
f.left_expr.cased_value == rname &&
f.right_expr.is_a?(Puppet::Pops::Model::QualifiedName) &&
f.right_expr.value == 'new'
end
raise ArgumentError, "missing #{rname}.new call" unless has_ctor Try / catch
begin
loader.load_typed(typed_name)
rescue ArgumentError => e
raise unless e.message.include?('.new found')
warn "file is not a resource type definition: #{e.message}"
end Prevention
- Start resource type files from a verified Resource::ResourceTypeImpl.new template
- Keep data type aliases out of the resource type path
- Validate the file statically after generating it
When it happens
Trigger: `statements.find` returns nil: the file contains no `Resource::ResourceTypeImpl.new(...)` call -- e.g. a class definition, a data type alias (`type X = ...`), or other Puppet code placed where a resource type implementation is loaded from.
Common situations: Putting an old-style custom type or a data type alias in the path the resource-type loader scans; partially migrated files; misunderstanding which Puppet feature uses this file format.
Related errors
- The code loaded from %{source_ref} does not create the resou
- The code loaded from %{source_ref} must contain only the cre
- The code loaded from %{source} contains additional logic - c
- The code loaded from %{source} contains additional logic - c
- The code loaded from %{source_ref} does not define the resou
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/f4508feb67fbc899.
Report an issue: GitHub.