puppetlabs/puppet · error · ArgumentError

No format matches the given format name or mime-type (%{form

Error message

No format matches the given format name or mime-type (%{format})

What it means

format_to_canonical_name normalizes whatever the caller calls a 'format' — a Format instance, a mime-type string matching \w+/\w+ (e.g. 'application/json'), or a bare name — to the canonical name of a registered format. If every lookup returns nil (nothing registered under that name or mime type in this process), ArgumentError is raised: the format is unknown here, regardless of whether other Puppet versions or plugins know it.

Source

Thrown at lib/puppet/network/format_handler.rb:69

    @formats.values.find { |format| format.mime == mimetype }
  end

  # Return a format name given:
  #  * a format name
  #  * a mime-type
  #  * a format instance
  def self.format_to_canonical_name(format)
    case format
    when Puppet::Network::Format
      out = format
    when %r{\w+/\w+}
      out = mime(format)
    else
      out = format(format)
    end

    if out.nil?
      raise ArgumentError, _("No format matches the given format name or mime-type (%{format})") % { format: format }
    end

    out.name
  end

  # Determine which of the accepted formats should be used given what is supported.
  #
  # @param accepted [Array<String, Symbol>] the accepted formats in a form a
  #   that generally conforms to an HTTP Accept header. Any quality specifiers
  #   are ignored and instead the formats are simply in strict preference order
  #   (most preferred is first)
  # @param supported [Array<Symbol>] the names of the supported formats (the
  #   most preferred format is first)
  # @return [Array<Puppet::Network::Format>] the most suitable formats that
  #   are both accepted and supported
  # @api private
  def self.most_suitable_formats_for(accepted, supported)
    accepted.collect do |format|

View on GitHub (pinned to e227c27540)

Solutions

  1. Use formats registered in this process: json and yaml always, msgpack when its gem is loaded (check Puppet::Network::FormatHandler.formats).
  2. Register the custom format before use: Puppet::Network::FormatHandler.create(:foo, :mime => 'application/foo') { ... } in a plugin loaded on every node that handles it.
  3. Send well-formed mime types ('application/json') so the mime branch can match.
  4. For legacy clients, serve json — pson was removed and must not be requested.

Example fix

# before
Puppet::Network::FormatHandler.format_to_canonical_name('pson')
# => ArgumentError: No format matches the given format name or mime-type (pson)

# after
Puppet::Network::FormatHandler.format_to_canonical_name('json') # => :json
Defensive patterns

Strategy: validation

Validate before calling

registered = Puppet::Network::FormatHandler.formats.map(&:to_s)
chosen = registered.include?(requested.to_s) ? requested : 'json'
name = Puppet::Network::FormatHandler.format_to_canonical_name(chosen)

Type guard

def known_format?(name_or_mime)
  return true if name_or_mime.is_a?(Puppet::Network::Format)
  str = name_or_mime.to_s
  !Puppet::Network::FormatHandler.format(str).nil? ||
    (str =~ %r{\w+/\w+} && !Puppet::Network::FormatHandler.mime(str).nil?)
end

Try / catch

begin
  canonical = Puppet::Network::FormatHandler.format_to_canonical_name(raw)
rescue ArgumentError
  canonical = :json # json is registered in every Puppet
end

Prevention

When it happens

Trigger: Any path that canonicalizes caller input: REST request handling with an unknown Content-Type/Accept ('application/x-foo'), Puppet::Network::FormatHandler.format_to_canonical_name('pson') on Puppet versions where pson was removed, or convert_from(:msgpack, ...) without the msgpack gem loaded.

Common situations: Older tooling still asking for 'pson' against Puppet 6+; typo'd format parameters; custom formats registered by a plugin that is not loaded on this node; mime strings that do not match the \w+/\w+ pattern.

Related errors


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