{"record":{"id":"76912dc41963b9c7","repo":"puppetlabs/puppet","slug":"given-data-type-value-is-not-a-data-type-got-t","errorCode":null,"errorMessage":"Given data_type value is not a data type, got '%{type}'","messagePattern":"Given data_type value is not a data type, got '%(.+?)'","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pal/compiler.rb","lineNumber":196,"sourceCode":"    #   pal.create('Car', 'color' => 'black', 'make' => 't-ford')\n    #\n    # @param type_string [String] a puppet language data type\n    # @return [Puppet::Pops::Types::PAnyType] the data type\n    #\n    def type(type_string)\n      Puppet::Pops::Types::TypeParser.singleton.parse(type_string)\n    end\n\n    # Creates a new instance of a given data type.\n    # @param data_type [String, Puppet::Pops::Types::PAnyType] the data type as a data type or in String form.\n    # @param arguments [Object] one or more arguments to the called `new` function\n    # @return [Object] an instance of the given data type,\n    #   or raises an error if it was not possible to parse data type or create an instance.\n    #\n    def create(data_type, *arguments)\n      t = data_type.is_a?(String) ? type(data_type) : data_type\n      unless t.is_a?(Puppet::Pops::Types::PAnyType)\n        raise ArgumentError, _(\"Given data_type value is not a data type, got '%{type}'\") % { type: t.class }\n      end\n\n      call_function('new', t, *arguments)\n    end\n\n    # Returns true if this is a compiler that compiles a catalog.\n    # This implementation returns `false`\n    # @return Boolan false\n    def has_catalog?\n      false\n    end\n\n    protected\n\n    def list_loadable_kind(kind, filter_regex = nil, error_collector = nil)\n      loader = internal_compiler.loaders.private_environment_loader\n      if filter_regex.nil?\n        loader.discover(kind, error_collector)","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pal/compiler.rb#L178-L214","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\npal.create(5, 3) # 5 is not a type\n\n// after\npal.create('Integer', 3)","handlingStrategy":"type-guard","validationCode":"raise ArgumentError, 'data_type must be a String or PAnyType' unless data_type.is_a?(String) || data_type.is_a?(Puppet::Pops::Types::PAnyType)","typeGuard":"def pal_creatable_type?(t)\n  t.is_a?(String) || t.is_a?(Puppet::Pops::Types::PAnyType)\nend","tryCatchPattern":"begin\n  pal.create(type_arg, *args)\nrescue ArgumentError => e\n  raise ArgumentError, \"invalid data type #{type_arg.inspect}\" if e.message.include?('not a data type')\n  raise\nend","preventionTips":["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"],"tags":["puppet","pal","ruby","type-validation","argument-error"],"backgroundTag":"invalid-data-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}