{"record":{"id":"f185e229ad013beb","repo":"puppetlabs/puppet","slug":"package-hash-name-version-hash-ensure-i","errorCode":null,"errorMessage":"Package #{hash[:name]}, version #{hash[:ensure]} is in error state: #{hash[:error]}","messagePattern":"Package #(.+?), version #(.+?) is in error state: #(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/package/dpkg.rb","lineNumber":162,"sourceCode":"          @resource[:name] = hash[:name]\n        end\n      end\n      output = dpkgquery(\n        \"-W\",\n        \"--showformat\",\n        self.class::DPKG_QUERY_FORMAT_STRING,\n        @resource[:name]\n      )\n      hash = self.class.parse_line(output)\n    rescue Puppet::ExecutionFailure\n      # dpkg-query exits 1 if the package is not found.\n      return { :ensure => :purged, :status => 'missing', :name => @resource[:name], :error => 'ok' }\n    end\n\n    hash ||= { :ensure => :absent, :status => 'missing', :name => @resource[:name], :error => 'ok' }\n\n    if hash[:error] != \"ok\"\n      raise Puppet::Error, \"Package #{hash[:name]}, version #{hash[:ensure]} is in error state: #{hash[:error]}\"\n    end\n\n    hash\n  end\n\n  def uninstall\n    dpkg \"-r\", @resource[:name]\n  end\n\n  def purge\n    dpkg \"--purge\", @resource[:name]\n  end\n\n  def hold\n    Tempfile.open('puppet_dpkg_set_selection') do |tmpfile|\n      tmpfile.write(\"#{@resource[:name]} hold\\n\")\n      tmpfile.flush\n      execute([:dpkg, \"--set-selections\"], :failonfail => false, :combine => false, :stdinfile => tmpfile.path.to_s)","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/package/dpkg.rb#L144-L180","documentation":"dpkg.rb:162: query runs dpkg-query and parses the ${Status} field into [:desired, :error, :status, ...]; the second word is dpkg's error flag. When it is anything other than 'ok' (typically 'reinstreq' — reinstatement required), the provider raises Puppet::Error naming the package, version and error state. It surfaces dpkg database/packages in a broken, half-completed state that must be repaired before management can proceed.","triggerScenarios":"A package resource (or `puppet resource package` enumeration reaching this code) for a package whose dpkg status is e.g. 'install reinstreq half-installed' — an interrupted dpkg run (killed mid-install, disk full, crash during postinst, power loss) left the package in an error state.","commonSituations":"dpkg interrupted by OOM/timeout during a CI agent run; disk filled mid-install; broken postinst script aborting the transaction; partially upgraded systems after a failed `apt-get upgrade`.","solutions":["Repair dpkg on the node: `dpkg --configure -a` then `apt-get -f install` (or `dpkg --remove --force-remove-reinstreq <pkg>` for a package that cannot be reconfigured).","Investigate why it broke: check /var/log/dpkg.log, disk space (`df -h /var /usr`), and the failing postinst.","Re-run the puppet agent once the package reports a clean status (`dpkg-query -W -f='${Status}' <pkg>` shows 'ok')."],"exampleFix":"# before: query raises 'package foo, version 1.2 is in error state: reinstreq'\n# repair on the node:\n#   sudo dpkg --configure -a\n#   sudo apt-get -f install\n# after\npackage { 'foo': ensure => installed }  # applies cleanly","handlingStrategy":"validation","validationCode":"# pre-flight: any package in an error state?\nout = `dpkg-query -W -f='${Status}' 2>/dev/null`.lines\nbad = `dpkg --audit 2>/dev/null`\nraise \"dpkg needs repair (dpkg --configure -a):\\n#{bad}\" unless bad.empty?","typeGuard":null,"tryCatchPattern":"begin\n  provider.query\nrescue Puppet::Error => e\n  raise unless e.message =~ /is in error state/\n  # run repair, then retry the puppet run once\n  system('dpkg --configure -a && apt-get -f install') or raise\n  retry\nend","preventionTips":["Run `dpkg --audit` in node bootstrap/pre-flight to catch broken states before puppet applies.","Avoid killing agent runs mid-package-install (OOM, timeouts) — that is the usual cause of reinstreq states.","Alert on dpkg.log entries containing 'status * error' or half-configured transitions."],"tags":["puppet","dpkg","debian","packages","corrupt-state"],"backgroundTag":"dpkg-package-error-state","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}