{"record":{"id":"34a50023833fbf67","repo":"puppetlabs/puppet","slug":"invalid-name-field-in-metadata-json-err","errorCode":null,"errorMessage":"Invalid 'name' field in metadata.json: %{err}","messagePattern":"Invalid 'name' field in metadata\\.json: %(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/module_tool/metadata.rb","lineNumber":190,"sourceCode":"    # Validates that the given module name is both namespaced and well-formed.\n    def validate_name(name)\n      return if name =~ %r{\\A[a-z0-9]+[-/][a-z][a-z0-9_]*\\Z}i\n\n      namespace, modname = name.split(%r{[-/]}, 2)\n      modname = :namespace_missing if namespace == ''\n\n      err = case modname\n            when nil, '', :namespace_missing\n              _(\"the field must be a namespaced module name\")\n            when /[^a-z0-9_]/i\n              _(\"the module name contains non-alphanumeric (or underscore) characters\")\n            when /^[^a-z]/i\n              _(\"the module name must begin with a letter\")\n            else\n              _(\"the namespace contains non-alphanumeric characters\")\n            end\n\n      raise ArgumentError, _(\"Invalid 'name' field in metadata.json: %{err}\") % { err: err }\n    end\n\n    # Validates that the version string can be parsed as per SemVer.\n    def validate_version(version)\n      return if SemanticPuppet::Version.valid?(version)\n\n      err = _(\"version string cannot be parsed as a valid Semantic Version\")\n      raise ArgumentError, _(\"Invalid 'version' field in metadata.json: %{err}\") % { err: err }\n    end\n\n    # Validates that the given _value_ is a symbolic name that starts with a letter\n    # and then contains only letters, digits, or underscore. Will raise an ArgumentError\n    # if that's not the case.\n    #\n    # @param value [Object] The value to be tested\n    def validate_data_provider(value)\n      if value.is_a?(String)\n        unless value =~ /^[a-zA-Z][a-zA-Z0-9_]*$/","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/module_tool/metadata.rb#L172-L208","documentation":"Puppet::ModuleTool::Metadata#validate_name enforces Forge naming: the name must match \\A[a-z0-9]+[-/][a-z][a-z0-9_]*\\Z — a non-empty namespace, a '-' or '/' separator, and a module part starting with a letter, alphanumeric/underscore only. Any other shape raises ArgumentError with a reason selected by the case chain (missing namespace, illegal characters, bad start, bad namespace). It runs whenever metadata.json is parsed (line 127).","triggerScenarios":"A metadata.json with name 'stdlib' (no namespace), 'puppet-labs/stdlib' or 'puppet 4-stdlib' (illegal characters), 'puppetlabs/4stdlib' (module part must begin with a letter), or 'puppet labs/stdlib' (space in namespace).","commonSituations":"Hand-writing metadata.json without the author prefix; copy-paste from Rubygems-style names ('puppetlabs-stdlib' is fine but 'stdlib' alone is not); names containing hyphens in the module part; metadata written by generators that never validated the format.","solutions":["Set name to '<author>-<module>' or '<author>/<module>', e.g. 'puppetlabs-stdlib', all lowercase","Make the module part start with a letter and use only [a-z0-9_]","Rename the module directory to match the short name (stdlib for puppetlabs-stdlib) so Puppet resolves it correctly","Re-validate by re-running `puppet module build` or parsing the file with Puppet::ModuleTool::Metadata"],"exampleFix":"// before - metadata.json\n\"name\": \"stdlib\",\n\n// after\n\"name\": \"puppetlabs-stdlib\",","handlingStrategy":"validation","validationCode":"VALID_NAME = /\\A[a-z0-9]+[-\\/][a-z][a-z0-9_]*\\Z/i\n\nname = JSON.parse(File.read('metadata.json'))['name']\nabort \"invalid module name '#{name}' — expected '<author>-<module>' or '<author>/<module>'\" unless name =~ VALID_NAME","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::ModuleTool::Metadata.from_hash('name' => raw_name)\nrescue ArgumentError => e\n  raise unless e.message =~ /Invalid 'name' field/\n  raw_name = \"acme-#{raw_name.tr('^a-zA-Z0-9_', '')}\".downcase  # repair, then retry\n  retry\nend","preventionTips":["Always generate new modules with `puppet module generate <author>-<name>` to get a valid skeleton","Keep the module name lowercase, namespaced, and matching the directory short name","Add a metadata.json lint step (metadata-json-lint) to CI"],"tags":["puppet","module-tool","metadata","module-name","validation"],"backgroundTag":"invalid-module-name","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}