puppetlabs/puppet · error · ArgumentError
The code loaded from %{source_ref} does not seem to be a Pup
Error message
The code loaded from %{source_ref} does not seem to be a Puppet 5x API data type - no create_type call. What it means
Raised by RubyDataTypeInstantiator when Ruby source being loaded as a data type does not contain a Puppet::DataTypes.create_type call (a simple regex gate on the source string before eval). Ruby data types must be defined through that API; anything else fails fast instead of being evaluated.
Source
Thrown at lib/puppet/pops/loader/ruby_data_type_instantiator.rb:19
# frozen_string_literal: true
# The RubyTypeInstantiator instantiates a data type from the ruby source
# that calls Puppet::DataTypes.create_type.
#
class Puppet::Pops::Loader::RubyDataTypeInstantiator
# Produces an instance of class derived from PAnyType class with the given typed_name, or fails with an error if the
# given ruby source does not produce this instance when evaluated.
#
# @param loader [Puppet::Pops::Loader::Loader] The loader the type is associated with
# @param typed_name [Puppet::Pops::Loader::TypedName] the type / name of the type to load
# @param source_ref [URI, String] a reference to the source / origin of the ruby code to evaluate
# @param ruby_code_string [String] ruby code in a string
#
# @return [Puppet::Pops::Types::PAnyType] - an instantiated data type associated with the given loader
#
def self.create(loader, typed_name, source_ref, ruby_code_string)
unless ruby_code_string.is_a?(String) && ruby_code_string =~ /Puppet::DataTypes\.create_type/
raise ArgumentError, _("The code loaded from %{source_ref} does not seem to be a Puppet 5x API data type - no create_type call.") % { source_ref: source_ref }
end
# make the private loader available in a binding to allow it to be passed on
loader_for_type = loader.private_loader
here = get_binding(loader_for_type)
created = eval(ruby_code_string, here, source_ref, 1) # rubocop:disable Security/Eval
unless created.is_a?(Puppet::Pops::Types::PAnyType)
raise ArgumentError, _("The code loaded from %{source_ref} did not produce a data type when evaluated. Got '%{klass}'") % { source_ref: source_ref, klass: created.class }
end
unless created.name.casecmp(typed_name.name) == 0
raise ArgumentError, _("The code loaded from %{source_ref} produced mis-matched name, expected '%{type_name}', got %{created_name}") % { source_ref: source_ref, type_name: typed_name.name, created_name: created.name }
end
created
end
# Produces a binding where the given loader is bound as a local variable (loader_injected_arg). This variable can be used in loaded
# ruby code - e.g. to call Puppet::Function.create_loaded_function(:name, loader,...)View on GitHub (pinned to e227c27540)
Solutions
- Define the type with Puppet::DataTypes.create_type('<name>') do ... end in the Ruby file
- If the file is Puppet language (type alias), move it to the Puppet-language type location instead of the Ruby path
- Verify the file named by source_ref is the one you intended to load
Example fix
# before - lib/puppet/datatypes/mymod/port.rb
Puppet::Functions.create_function(:'mymod::port') do
def port(x); x; end
end
# after
Puppet::DataTypes.create_type('mymod::port') do
interface <<-PUPPET
attributes => {
value => { type => Integer, value => 8080 }
}
PUPPET
end Defensive patterns
Strategy: validation
Validate before calling
raise ArgumentError, "#{path} is not a Puppet 5x data type" unless ruby_source.is_a?(String) && ruby_source =~ /Puppet::DataTypes\.create_type/ Try / catch
begin
type = loader.load_typed(typed_name)
rescue ArgumentError => e
raise unless e.message.include?('no create_type call')
warn "not a Ruby data type: #{e.message}"
end Prevention
- Keep only Puppet::DataTypes.create_type files in the Ruby data type path
- During 3x/4x migration, verify each file uses the API matching its directory
- Grep shipped .rb data type files for create_type in CI
When it happens
Trigger: `ruby_code_string !~ /Puppet::DataTypes\.create_type/`: the .rb file resolved for a data type name lacks the literal call -- e.g. it defines a 4x function via Puppet::Functions.create_function, or is plain Ruby with no type creation.
Common situations: Placing a non-data-type .rb file where the data type loader resolves it; refactoring away from the DataTypes API; wrong name-to-file mapping causing the loader to open the wrong source.
Related errors
- The code loaded from %{source_ref} did not produce a data ty
- The code loaded from %{source_ref} produced mis-matched name
- The code loaded from %{source_ref} does not seem to be a Pup
- The code loaded from %{source_ref} did not produce a Functio
- The code loaded from %{source_ref} does not seem to be a Pup
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/69e30d1e08268d06.
Report an issue: GitHub.