{"record":{"id":"c07be21405c1bafd","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-produced-mis-ma","errorCode":null,"errorMessage":"The code loaded from %{source_ref} produced mis-matched name, expected '%{type_name}', got %{created_name}","messagePattern":"The code loaded from %(.+?) produced mis-matched name, expected '%(.+?)', got %(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/ruby_data_type_instantiator.rb","lineNumber":30,"sourceCode":"  # @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":12,"sourceCodeEnd":44,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/ruby_data_type_instantiator.rb#L12-L44","documentation":"Raised by RubyDataTypeInstantiator when the created data type's name does not match (case-insensitively, via casecmp) the typed name the loader requested. The name string given to Puppet::DataTypes.create_type must equal the name derived from the file name and module path.","triggerScenarios":"`created.name.casecmp(typed_name.name) != 0`: e.g. create_type('mymod::port2') in a file loaded as mymod::port, or a missing module namespace segment.","commonSituations":"Renaming the file without updating the create_type name string (or vice versa); copy-paste; namespacing mistakes when moving types between modules.","solutions":["Set the create_type name to the exact namespaced name derived from module + file path","Rename the file to match the create_type name if that is the desired name","Note the comparison is case-insensitive, so a mismatch here means a real name difference, not casing"],"exampleFix":"# before - lib/puppet/datatypes/mymod/port.rb\nPuppet::DataTypes.create_type('mymod::port_ssl') { ... }\n\n# after\nPuppet::DataTypes.create_type('mymod::port') { ... }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  type = loader.load_typed(typed_name)\nrescue ArgumentError => e\n  raise unless e.message.include?('mis-matched name')\n  warn \"data type name mismatch: #{e.message}\"\nend","preventionTips":["Derive the create_type name from module + file path","Rename file and name string in the same change","Prefer Puppet-language type aliases unless Ruby behavior is required"],"tags":["puppet","data-type","naming","ruby","loader"],"backgroundTag":"puppet-definition-name-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}