puppetlabs/puppet · error · Puppet::Error

Could not match package info '%{pkgstuff}'

Error message

Could not match package info '%{pkgstuff}'

What it means

Raised in `latest` (lib/puppet/provider/package/ports.rb:47) of the FreeBSD ports provider. It takes the last line of `portversion -v <name>` output and requires the first column (`pkgstuff`, e.g. `www/nginx-1.2.3`) to end in a dash-version suffix; when it does not, the version cannot be extracted and Puppet::Error 'Could not match package info' is raised.

Source

Thrown at lib/puppet/provider/package/ports.rb:47

    begin
      output = portversion(*cmd)
    rescue Puppet::ExecutionFailure => e
      raise Puppet::Error.new(output, e)
    end
    line = output.split("\n").pop

    unless line =~ /^(\S+)\s+(\S)\s+(.+)$/
      # There's no "latest" version, so just return a placeholder
      return :latest
    end

    pkgstuff = Regexp.last_match(1)
    match = Regexp.last_match(2)
    info = Regexp.last_match(3)

    unless pkgstuff =~ /^\S+-([^-\s]+)$/
      raise Puppet::Error,
            _("Could not match package info '%{pkgstuff}'") % { pkgstuff: pkgstuff }
    end

    version = Regexp.last_match(1)

    if match == "=" or match == ">"
      # we're up to date or more recent
      return version
    end

    # Else, we need to be updated; we need to pull out the new version

    unless info =~ /\((\w+) has (.+)\)/
      raise Puppet::Error,
            _("Could not match version info '%{info}'") % { info: info }
    end

    source = Regexp.last_match(1)

View on GitHub (pinned to e227c27540)

Solutions

  1. Run `portversion -v <name>` and inspect the first column the error quotes.
  2. Update the ports tree (`portsnap fetch update`) and reinstall ports-mgmt/portupgrade to current versions.
  3. If the port moved, update the resource to the new origin.
  4. Clean stale package registrations (`pkgdb -F` in the portupgrade world) so portversion output is well-formed.
Defensive patterns

Strategy: fallback

Validate before calling

# Confirm portversion emits a parseable first column before the run
line=$(portversion -v "${name}" 2>/dev/null | tail -1)
echo "$line" | awk '{ print $1 }' | grep -Eq '\S+-[^-\s]+$' || echo "unparseable portversion output - update ports/portupgrade"

Try / catch

begin
  latest = provider.latest
rescue Puppet::Error => e
  raise unless e.message =~ /Could not match package info/
  latest = :latest # degrade gracefully: treat as unknown/uptodate
end

Prevention

When it happens

Trigger: portversion printing a first column with no `-version` part: a moved/removed port whose entry lost its version, an origin-only line like `www/nginx`, or column formatting that shifted under the regex.

Common situations: Ports tree mid-move (MOVED entries) or out of sync with installed packages; portupgrade/portversion tools older than the current ports layout; leftover stale package database entries.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/b0cc7346adf17bef. Report an issue: GitHub.