puppetlabs/puppet · error · ArgumentError
Given data_type value is not a data type, got '%{type}'
Error message
Given data_type value is not a data type, got '%{type}' What it means
Raised by Puppet::Pal::Compiler#create when the data_type argument is neither a String (which PAL would parse as a type expression) nor an instance of Puppet::Pops::Types::PAnyType. create() is the PAL API for instantiating a value from a type via the 'new' function; after optionally parsing a String it requires an actual Pops type object.
Source
Thrown at lib/puppet/pal/compiler.rb:196
# pal.create('Car', 'color' => 'black', 'make' => 't-ford')
#
# @param type_string [String] a puppet language data type
# @return [Puppet::Pops::Types::PAnyType] the data type
#
def type(type_string)
Puppet::Pops::Types::TypeParser.singleton.parse(type_string)
end
# Creates a new instance of a given data type.
# @param data_type [String, Puppet::Pops::Types::PAnyType] the data type as a data type or in String form.
# @param arguments [Object] one or more arguments to the called `new` function
# @return [Object] an instance of the given data type,
# or raises an error if it was not possible to parse data type or create an instance.
#
def create(data_type, *arguments)
t = data_type.is_a?(String) ? type(data_type) : data_type
unless t.is_a?(Puppet::Pops::Types::PAnyType)
raise ArgumentError, _("Given data_type value is not a data type, got '%{type}'") % { type: t.class }
end
call_function('new', t, *arguments)
end
# Returns true if this is a compiler that compiles a catalog.
# This implementation returns `false`
# @return Boolan false
def has_catalog?
false
end
protected
def list_loadable_kind(kind, filter_regex = nil, error_collector = nil)
loader = internal_compiler.loaders.private_environment_loader
if filter_regex.nil?
loader.discover(kind, error_collector)View on GitHub (pinned to e227c27540)
Solutions
- Pass the type in String form, e.g. pal.create('Integer', 5) or pal.create('Array[String]')
- Or pass a real Pops type: Puppet::Pops::Types::TypeParser.singleton.parse('Optional[Integer]') or Puppet::Pops::Types::TypeFactory.integer
- If the value comes from user input, validate it is a String and let create() do the parsing
Example fix
// before
pal.create(5, 3) # 5 is not a type
// after
pal.create('Integer', 3) Defensive patterns
Strategy: type-guard
Validate before calling
raise ArgumentError, 'data_type must be a String or PAnyType' unless data_type.is_a?(String) || data_type.is_a?(Puppet::Pops::Types::PAnyType)
Type guard
def pal_creatable_type?(t) t.is_a?(String) || t.is_a?(Puppet::Pops::Types::PAnyType) end
Try / catch
begin
pal.create(type_arg, *args)
rescue ArgumentError => e
raise ArgumentError, "invalid data type #{type_arg.inspect}" if e.message.include?('not a data type')
raise
end Prevention
- Always pass type expressions as strings from user input and let PAL parse them
- When constructing types programmatically, build them with Puppet::Pops::Types::TypeFactory
When it happens
Trigger: Calling compiler.create(42), create(SomeRubyClass), create(:symbol) or create(nil) - anything that is not a String and not a Pops type. Passing PIntegerType/PArrayType/PStructType is fine since all derive from PAnyType; a String that fails parsing instead raises from TypeParser.
Common situations: Ruby tools embedding PAL that pass a Ruby class, constant or symbol where a type name is expected; passing an already-created Ruby value instead of its Puppet type; mixing up TypeParser results with raw strings.
Related errors
- Given variables must be a hash, got %{type}
- puppet.tasks/unparseable-metadata
- manifest_file or code_string cannot be given when configured
- A block must be given to 'in_tmp_environment'
- A block must be given to 'in_environment'
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/76912dc41963b9c7.
Report an issue: GitHub.