{"record":{"id":"a93ab9280bbe7072","repo":"puppetlabs/puppet","slug":"could-not-find-package-name","errorCode":null,"errorMessage":"Could not find package %{name}","messagePattern":"Could not find package %(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/package/apt.rb","lineNumber":178,"sourceCode":"    # rubocop:disable Style/RedundantCondition\n    if source\n      cmd << source\n    else\n      cmd << str\n    end\n    # rubocop:enable Style/RedundantCondition\n\n    unhold if properties[:mark] == :hold\n    begin\n      aptget(*cmd)\n    ensure\n      hold if @resource[:mark] == :hold\n    end\n\n    # If a source file was specified, we must make sure the expected version was installed from specified file\n    if source && !%i[present installed].include?(should)\n      is = query\n      raise Puppet::Error, _(\"Could not find package %{name}\") % { name: name } unless is\n\n      version = is[:ensure]\n\n      raise Puppet::Error, _(\"Failed to update to version %{should}, got version %{version} instead\") % { should: should, version: version } unless\n        insync?(version)\n    end\n  end\n\n  # What's the latest package version available?\n  def latest\n    output = aptcache :policy, @resource[:name]\n\n    if output =~ /Candidate:\\s+(\\S+)\\s/\n      Regexp.last_match(1)\n    else\n      err _(\"Could not find latest version\")\n      nil\n    end","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/package/apt.rb#L160-L196","documentation":"apt.rb:178: when a package was installed with an explicit `source` file and an ensure that is not :present/:installed, the provider re-queries dpkg afterwards to confirm the install. If query returns nil (dpkg-query cannot find the package at all), it raises 'Could not find package %{name}'. This means the .deb staged via source installed something whose dpkg name differs from the resource title/name — or the install silently did nothing.","triggerScenarios":"package resource with both `source => '/path/or/url/to.deb'` and `ensure => '1.2.3'` (a concrete version), where the Package: field inside the .deb does not equal the resource name (e.g. resource title 'foo' but the deb ships package 'foo-tools'), or the deb file is corrupt so dpkg never registered it.","commonSituations":"Using the resource title as a descriptive label instead of the real package name; renaming debs upstream; versioned deb artifacts where the name changes between versions (daemon vs -bin packages); a source URL that returned an HTML error page instead of a deb.","solutions":["Check the real package name inside the artifact: `dpkg-deb -I /path/to.deb` (or `dpkg-deb -f /path/to.deb Package`) and make the resource name match it exactly.","Set the resource `name` explicitly if the title must stay descriptive: `package { 'label': name => 'real-pkg-name', ... }`.","Verify the staged file is a valid deb (file(1), dpkg-deb --info) and that it was actually installed (dpkg -l)."],"exampleFix":"# before\npackage { 'riak': ensure => '2.2.5', source => '/tmp/riak.deb' } # deb actually ships 'riak-2'\n\n# after\npackage { 'riak': name => 'riak-2', ensure => '2.2.5', source => '/tmp/riak.deb' }","handlingStrategy":"validation","validationCode":"# confirm name/version in the artifact before puppet applies\npkg  = `dpkg-deb -f /tmp/foo.deb Package`.strip\nfail \"resource name must be #{pkg}\" unless pkg == 'foo'","typeGuard":null,"tryCatchPattern":"begin\n  apt_provider.install\nrescue Puppet::Error => e\n  raise unless e.message =~ /Could not find package/\n  # artifact/name mismatch: inspect dpkg-deb -I output, fix resource name, re-run\n  Puppet.err(e.message); raise\nend","preventionTips":["Always cross-check the deb's Package field (dpkg-deb -f <deb> Package) against the resource name in CI.","Use `name =>` explicitly when titles are descriptive.","Fail loudly at build time if staged artifacts are not valid debs (file(1) check)."],"tags":["puppet","apt","debian","packages","package-name-mismatch"],"backgroundTag":"package-install-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}