{"record":{"id":"4f523e226b9c9383","repo":"puppetlabs/puppet","slug":"data-type-load-error-for-type-type-name-me","errorCode":null,"errorMessage":"Data Type Load Error for type '%{type_name}': %{message}","messagePattern":"Data Type Load Error for type '%(.+?)': %(.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/datatypes.rb","lineNumber":135,"sourceCode":"#\n#     # This load_file is optional and only needed in case\n#     # the implementation is not loaded by other means.\n#     load_file 'puppetx/auth/user'\n#\n#     implementation_class PuppetX::Auth::User\n#   end\n#\nmodule Puppet::DataTypes\n  def self.create_type(type_name, &block)\n    # Ruby < 2.1.0 does not have method on Binding, can only do eval\n    # and it will fail unless protected with an if defined? if the local\n    # variable does not exist in the block's binder.\n    #\n\n    loader = block.binding.eval('loader_injected_arg if defined?(loader_injected_arg)')\n    create_loaded_type(type_name, loader, &block)\n  rescue StandardError => e\n    raise ArgumentError, _(\"Data Type Load Error for type '%{type_name}': %{message}\") % { type_name: type_name, message: e.message }\n  end\n\n  def self.create_loaded_type(type_name, loader, &block)\n    builder = TypeBuilder.new(type_name.to_s)\n    api = TypeBuilderAPI.new(builder).freeze\n    api.instance_eval(&block)\n    builder.create_type(loader)\n  end\n\n  # @api private\n  class TypeBuilder\n    attr_accessor :interface, :implementation, :implementation_class\n\n    def initialize(type_name)\n      @type_name = type_name\n      @implementation = nil\n      @implementation_class = nil\n    end","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/datatypes.rb#L117-L153","documentation":"Puppet::DataTypes.create_type wraps the entire Ruby data-type definition block: any StandardError raised while building the type (unparsable interface string, duplicate interface/implementation declarations, NameError inside the implementation, load_file of a missing file) is re-raised as ArgumentError 'Data Type Load Error for type X: <original message>'. The text after the colon is the underlying exception and identifies the true fault.","triggerScenarios":"Authoring Puppet::DataTypes.create_type('My::Type') { ... } in lib/puppet/datatypes with an interface string that fails to parse; declaring interface or implementation twice; the implementation block referencing an undefined constant; load_file pointing at a nonexistent file.","commonSituations":"First drafts of Ruby data types in a module; refactors that break the interface string; Puppet upgrades that made the parser stricter.","solutions":["Read the message after 'Data Type Load Error for type X: ' — it is the root-cause exception text; fix that first","Sanity-check the interface string by parsing it: Puppet::Pops::Parser::EvaluatingParser.new.parse_string(\"{ #{iface} }\")","Reproduce in isolation: place the type in a scratch module and run `puppet apply -e 'notice(My::Type)'`"],"exampleFix":"# before\nPuppet::DataTypes.create_type('Bad') { interface 'attributes => {' }  # unbalanced braces\n# after\nPuppet::DataTypes.create_type('Good') { interface 'attributes => { value => String }' }","handlingStrategy":"try-catch","validationCode":"# fail fast with a clean message while loading type files\nbegin\n  Puppet::DataTypes.create_type(name, &block)\nrescue ArgumentError => e\n  raise unless e.message =~ /Data Type Load Error/\n  raise \"#{name}: #{e.message}\"\nend","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::DataTypes.create_type('My::Type', &block)\nrescue ArgumentError => e\n  if e.message.start_with?('Data Type Load Error')\n    # the suffix is the original exception's message — log it, fix the type definition\n    Puppet.err e.message\n  else\n    raise\n  end\nend","preventionTips":["Parse-check interface strings with EvaluatingParser during development","Load each new data type in isolation (`puppet apply -e 'notice(My::Type)'`) before shipping"],"tags":["puppet","data-types","pcore","type-loading","ruby-api"],"backgroundTag":"type-loading-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}