puppetlabs/puppet · error · Puppet::Network::FormatHandler::FormatError
Could not mime to %{format}: %{err}
Error message
Could not mime to %{format}: %{err} What it means
Instance-level FormatSupport#mime resolves the mime type for a format and wraps failures as FormatError 'Could not mime to %{format}: %{err}'. Since Format#mime is just an attribute read on the format object, the wrapped error nearly always comes from get_format: the requested format is not registered in this process. It looks like a serialization error but is a format-lookup error.
Source
Thrown at lib/puppet/network/format_support.rb:125
Puppet::Util::Json.dump(to_data_hash, *args)
end
def render(format = nil)
format ||= self.class.default_format
self.class.get_format(format).render(self)
rescue => err
# TRANSLATORS "render" is a function name and should not be translated
raise Puppet::Network::FormatHandler::FormatError, _("Could not render to %{format}: %{err}") % { format: format, err: err }, err.backtrace
end
def mime(format = nil)
format ||= self.class.default_format
self.class.get_format(format).mime
rescue => err
# TRANSLATORS "mime" is a function name and should not be translated
raise Puppet::Network::FormatHandler::FormatError, _("Could not mime to %{format}: %{err}") % { format: format, err: err }, err.backtrace
end
def support_format?(name)
self.class.support_format?(name)
end
# @comment Document to_data_hash here as it is called as a hook from to_msgpack if it exists
# @!method to_data_hash(*args)
# @api public
# @abstract
# This method may be implemented to return a hash object that is used for serializing.
# The object returned by this method should contain all the info needed to instantiate it again.
# If the method exists it will be called from to_msgpack and other serialization methods.
# @return [Hash]
end
View on GitHub (pinned to e227c27540)
Solutions
- Call mime() with no argument — it falls back to the class default_format, which is always registered.
- Validate the name first: Puppet::Network::FormatHandler.formats.include?(name.to_sym).
- Load the plugin that registers the missing format.
- Catch the FormatError and fall back to the default format's mime type.
Example fix
# before content_type = obj.mime(params[:format]) # FormatError when unregistered # after known = Widget.supported_formats.map(&:to_s) fmt = known.include?(params[:format]) ? params[:format] : nil # nil → default_format content_type = obj.mime(fmt)
Defensive patterns
Strategy: validation
Validate before calling
known = Widget.supported_formats.map(&:to_s) fmt = known.include?(requested.to_s) ? requested : nil # nil arg → default_format content_type = widget.mime(fmt)
Try / catch
begin widget.mime(fmt) rescue Puppet::Network::FormatHandler::FormatError widget.mime # the default format is always registered end
Prevention
- Never feed raw request parameters into mime(); whitelist first.
- Prefer the no-argument form unless you must state a format.
- Register custom formats in plugins loaded on every consumer node.
- Test format plumbing against the exact Puppet versions deployed.
When it happens
Trigger: obj.mime(:bogus) or obj.mime(user_supplied_string) where the name is not a registered format; also defaulting to a format whose registering plugin failed to load.
Common situations: Passing request-derived format names into mime(); typos in format names; pluginsync not delivering a custom format; version skew where a format was removed.
Related errors
- #{klass} does not respond to #{intern_multiple_method}; can
- #{instance.class} does not respond to #{render_method}; can
- %{klass} does not respond to %{method}; can not render multi
- No format matches the given format name or mime-type (%{form
- Could not render_multiple to %{format}: %{err}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/2fb847862a222d68.
Report an issue: GitHub.