puppetlabs/puppet · error · ArgumentError
The code loaded from %{source_ref} did not produce a data ty
Error message
The code loaded from %{source_ref} did not produce a data type when evaluated. Got '%{klass}' What it means
Raised by RubyDataTypeInstantiator when the Ruby source passed the create_type regex gate but eval'ing it produced an object that is not a Puppet::Pops::Types::PAnyType. Puppet::DataTypes.create_type returns the created type instance, so the file's value (its last expression) must be that call; anything else fails here with the actual class reported.
Source
Thrown at lib/puppet/pops/loader/ruby_data_type_instantiator.rb:27
#
# @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,...)
#
def self.get_binding(loader_injected_arg)
binding
end
private_class_method :get_binding
end
View on GitHub (pinned to e227c27540)
Solutions
- Make Puppet::DataTypes.create_type(...) the last expression in the file
- Use the reported 'Got' class to identify the stray trailing expression and remove or reorder it
Example fix
# before
Puppet::DataTypes.create_type('mymod::port') { ... }
require 'yaml'
# after
require 'yaml'
Puppet::DataTypes.create_type('mymod::port') { ... } Defensive patterns
Strategy: try-catch
Type guard
def puppet_data_type?(obj) obj.is_a?(Puppet::Pops::Types::PAnyType) end
Try / catch
begin
type = loader.load_typed(typed_name)
rescue ArgumentError => e
raise unless e.message.include?('did not produce a data type')
warn "file does not evaluate to a data type: #{e.message}"
end Prevention
- End Ruby data type files with the create_type call
- Put requires and setup above the definition
- Load-test all data types after editing (e.g. a small script that loads each type)
When it happens
Trigger: `eval(ruby_code_string, here, source_ref, 1)` returns a non-PAnyType: statements after the create_type call change the file's value, or create_type is invoked conditionally so another expression becomes the result.
Common situations: Appending configuration, logging, or requires after the create_type block; storing the type in a variable without returning it.
Related errors
- The code loaded from %{source_ref} does not seem to be a Pup
- 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/aa8bbcc6a590b119.
Report an issue: GitHub.