{"record":{"id":"ceb5bb8dfb7efdd4","repo":"puppetlabs/puppet","slug":"failed-to-list-packages","errorCode":null,"errorMessage":"Failed to list packages","messagePattern":"Failed to list packages","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/package/rpm.rb","lineNumber":75,"sourceCode":"    '--nosignature' unless Puppet::Util::Package.versioncmp(current_version, '4.1') < 0\n  end\n\n  # rpm < 4.0.2 does not support --nodigest\n  def self.nodigest\n    '--nodigest' unless Puppet::Util::Package.versioncmp(current_version, '4.0.2') < 0\n  end\n\n  def self.instances\n    packages = []\n\n    # list out all of the packages\n    begin\n      execpipe(\"#{command(:rpm)} -qa #{nosignature} #{nodigest} --qf '#{self::NEVRA_FORMAT}' | sort\") { |process|\n        # now turn each returned line into a package object\n        nevra_to_multiversion_hash(process).each { |hash| packages << new(hash) }\n      }\n    rescue Puppet::ExecutionFailure => e\n      raise Puppet::Error, _(\"Failed to list packages\"), e.backtrace\n    end\n\n    packages\n  end\n\n  # Find the fully versioned package name and the version alone. Returns\n  # a hash with entries :instance => fully versioned package name, and\n  # :ensure => version-release\n  def query\n    # NOTE: Prior to a fix for issue 1243, this method potentially returned a cached value\n    # IF YOU CALL THIS METHOD, IT WILL CALL RPM\n    # Use get(:property) to check if cached values are available\n    cmd = [\"-q\", @resource[:name], self.class.nosignature.to_s, self.class.nodigest.to_s, \"--qf\", self.class::NEVRA_FORMAT.to_s]\n\n    begin\n      output = rpm(*cmd)\n    rescue Puppet::ExecutionFailure\n      return nil unless @resource.allow_virtual?","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/package/rpm.rb#L57-L93","documentation":"The rpm provider's self.instances shells out to 'rpm -qa --qf ... | sort' via execpipe and wraps any Puppet::ExecutionFailure as Puppet::Error 'Failed to list packages'. It fires during prefetch - any puppet run or 'puppet resource package' on an rpm-based host - when the rpm query itself fails, most commonly a corrupted rpm database in /var/lib/rpm.","triggerScenarios":"'rpm -qa' exiting non-zero: corrupted Berkeley DB (__db files) after a killed rpm/yum transaction, db lock contention with concurrent yum cron jobs, a pruned/unreadable rpmdb in minimal containers, or 'sort' failing because /tmp or /var is full.","commonSituations":"Interrupted yum/rpm transactions; rpm db locks held by unattended-upgrades; container base images with stripped rpm databases; disk-full conditions.","solutions":["Reproduce as root: 'rpm -qa' - expect errors like 'db5 error(-30969) from dbenv->open'","Rebuild the rpm database: 'rm -f /var/lib/rpm/__db.*; rpm --rebuilddb'","Free disk/inode space on /var and /tmp if full, then retry the agent run","For containers, use a base image with an intact rpmdb or confine to a provider that works there"],"exampleFix":"# before: rpm -qa fails with a db5 error and every puppet run aborts\nrm -f /var/lib/rpm/__db.*\nrpm --rebuilddb\n# after: 'rpm -qa | wc -l' returns a count and puppet runs complete","handlingStrategy":"validation","validationCode":"# Ruby: verify the rpm database is queryable before a run that prefetches packages\ndef rpm_db_healthy?\n  Puppet::Util::Execution.execute(['rpm', '-qa'], failonfail: false, combine: false).exitstatus.zero?\nend","typeGuard":null,"tryCatchPattern":"begin\n  instances = Puppet::Type.type(:package).provider(:rpm).instances\nrescue Puppet::Error => e\n  raise unless e.message == 'Failed to list packages'\n  Puppet.err('rpm -qa failed; run `rm -f /var/lib/rpm/__db.*; rpm --rebuilddb` then retry')\n  instances = []\nend","preventionTips":["Never kill -9 rpm/yum mid-transaction; let it finish or use --setopt timeout tuning","Monitor free space and inodes on /var and /tmp on rpm-based hosts","Include an 'rpm -qa' health check in image build pipelines"],"tags":["rpm","rpm-database","prefetch","package-listing","corruption"],"backgroundTag":"rpm-database-error","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}