{"record":{"id":"aa8bbcc6a590b119","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-did-not-produce","errorCode":null,"errorMessage":"The code loaded from %{source_ref} did not produce a data type when evaluated. Got '%{klass}'","messagePattern":"The code loaded from %(.+?) did not produce a data type when evaluated\\. Got '%(.+?)'","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/ruby_data_type_instantiator.rb","lineNumber":27,"sourceCode":"  #\n  # @param loader [Puppet::Pops::Loader::Loader] The loader the type is associated with\n  # @param typed_name [Puppet::Pops::Loader::TypedName] the type / name of the type to load\n  # @param source_ref [URI, String] a reference to the source / origin of the ruby code to evaluate\n  # @param ruby_code_string [String] ruby code in a string\n  #\n  # @return [Puppet::Pops::Types::PAnyType] - an instantiated data type associated with the given loader\n  #\n  def self.create(loader, typed_name, source_ref, ruby_code_string)\n    unless ruby_code_string.is_a?(String) && ruby_code_string =~ /Puppet::DataTypes\\.create_type/\n      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 }\n    end\n\n    # make the private loader available in a binding to allow it to be passed on\n    loader_for_type = loader.private_loader\n    here = get_binding(loader_for_type)\n    created = eval(ruby_code_string, here, source_ref, 1) # rubocop:disable Security/Eval\n    unless created.is_a?(Puppet::Pops::Types::PAnyType)\n      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 }\n    end\n    unless created.name.casecmp(typed_name.name) == 0\n      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 }\n    end\n\n    created\n  end\n\n  # Produces a binding where the given loader is bound as a local variable (loader_injected_arg). This variable can be used in loaded\n  # ruby code - e.g. to call Puppet::Function.create_loaded_function(:name, loader,...)\n  #\n  def self.get_binding(loader_injected_arg)\n    binding\n  end\n  private_class_method :get_binding\nend\n","sourceCodeStart":9,"sourceCodeEnd":44,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/ruby_data_type_instantiator.rb#L9-L44","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Appending configuration, logging, or requires after the create_type block; storing the type in a variable without returning it.","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"],"exampleFix":"# before\nPuppet::DataTypes.create_type('mymod::port') { ... }\nrequire 'yaml'\n\n# after\nrequire 'yaml'\nPuppet::DataTypes.create_type('mymod::port') { ... }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"def puppet_data_type?(obj)\n  obj.is_a?(Puppet::Pops::Types::PAnyType)\nend","tryCatchPattern":"begin\n  type = loader.load_typed(typed_name)\nrescue ArgumentError => e\n  raise unless e.message.include?('did not produce a data type')\n  warn \"file does not evaluate to a data type: #{e.message}\"\nend","preventionTips":["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)"],"tags":["puppet","data-type","ruby","loader","eval"],"backgroundTag":"puppet-data-type-load-validation","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}