{"record":{"id":"5b0ec231f0649afd","repo":"puppetlabs/puppet","slug":"could-not-determine-module-path","errorCode":null,"errorMessage":"Could not determine module path","messagePattern":"Could not determine module path","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/module_tool/applications/application.rb","lineNumber":46,"sourceCode":"        when Net::HTTPOK, Net::HTTPCreated\n          Puppet.notice success\n        else\n          errors = begin\n            Puppet::Util::Json.load(response.body)['error']\n          rescue\n            \"HTTP #{response.code}, #{response.body}\"\n          end\n          Puppet.warning \"#{failure} (#{errors})\"\n        end\n      end\n\n      def metadata(require_metadata = false)\n        return @metadata if @metadata\n\n        @metadata = Puppet::ModuleTool::Metadata.new\n\n        unless @path\n          raise ArgumentError, _(\"Could not determine module path\")\n        end\n\n        if require_metadata && !Puppet::ModuleTool.is_module_root?(@path)\n          raise ArgumentError, _(\"Unable to find metadata.json in module root at %{path} See https://puppet.com/docs/puppet/latest/modules_publishing.html for required file format.\") % { path: @path }\n        end\n\n        metadata_path = File.join(@path, 'metadata.json')\n\n        if File.file?(metadata_path)\n          File.open(metadata_path) do |f|\n            @metadata.update(Puppet::Util::Json.load(f))\n          rescue Puppet::Util::Json::ParseError => ex\n            raise ArgumentError, _(\"Could not parse JSON %{metadata_path}\") % { metadata_path: metadata_path }, ex.backtrace\n          end\n        end\n\n        if File.file?(File.join(@path, 'Modulefile'))\n          Puppet.warning _(\"A Modulefile was found in the root directory of the module. This file will be ignored and can safely be removed.\")","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/module_tool/applications/application.rb#L28-L64","documentation":"ModuleTool::Applications::Application#metadata raises ArgumentError('Could not determine module path') when @path is nil at the time metadata is loaded. The application base class (Installer, Uninstaller, Builder, etc.) expects the target module path to be set during initialization; a nil path means the constructor was given no resolvable directory (e.g. nil/empty name and no explicit path).","triggerScenarios":"Instantiating Puppet::ModuleTool::Applications::Installer or similar with options where neither a module name resolving to a directory nor an explicit :install_dir/:path produces a value, then calling #metadata or #run, which calls metadata and hits the `unless @path` branch.","commonSituations":"Programmatic use of the module_tool applications with missing options hash keys; a Rake task or wrapper that passes nil for the module directory; running from a cwd outside any module without --path so path derivation returns nil.","solutions":["Pass an explicit directory: run the command from the module root, or supply the path option (e.g. `puppet module build /path/to/module`).","If calling the API, ensure options include a resolvable target so @path is set before #run.","Check for typos in the path argument that make it non-existent and leave @path unset."],"exampleFix":"# before\nPuppet::ModuleTool::Applications::Installer.new(nil, :install_dir => dir).run\n\n# after\nPuppet::ModuleTool::Applications::Installer.new('puppetlabs-stdlib', :install_dir => dir).run","handlingStrategy":"validation","validationCode":"abort 'no module path: run from module root or pass --path/PATH' unless options[:install_dir] || Dir.pwd","typeGuard":null,"tryCatchPattern":"begin\n  app.run\nrescue ArgumentError => e\n  raise if e.message != 'Could not determine module path'\n  abort 'run this command from the module root or specify the target path'\nend","preventionTips":["Always pass an explicit target directory when invoking ModuleTool applications programmatically.","Verify the module root (contains metadata.json) before constructing the application.","Use Puppet::ModuleTool.find_module_root(Dir.pwd) and abort when it returns nil."],"tags":["puppet","module-tool","missing-path","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}