{"record":{"id":"2fb847862a222d68","repo":"puppetlabs/puppet","slug":"could-not-mime-to-format-err","errorCode":null,"errorMessage":"Could not mime to %{format}: %{err}","messagePattern":"Could not mime to %(.+?): %(.+?)","errorType":"exception","errorClass":"Puppet::Network::FormatHandler::FormatError","httpStatus":null,"severity":"error","filePath":"lib/puppet/network/format_support.rb","lineNumber":125,"sourceCode":"    Puppet::Util::Json.dump(to_data_hash, *args)\n  end\n\n  def render(format = nil)\n    format ||= self.class.default_format\n\n    self.class.get_format(format).render(self)\n  rescue => err\n    # TRANSLATORS \"render\" is a function name and should not be translated\n    raise Puppet::Network::FormatHandler::FormatError, _(\"Could not render to %{format}: %{err}\") % { format: format, err: err }, err.backtrace\n  end\n\n  def mime(format = nil)\n    format ||= self.class.default_format\n\n    self.class.get_format(format).mime\n  rescue => err\n    # TRANSLATORS \"mime\" is a function name and should not be translated\n    raise Puppet::Network::FormatHandler::FormatError, _(\"Could not mime to %{format}: %{err}\") % { format: format, err: err }, err.backtrace\n  end\n\n  def support_format?(name)\n    self.class.support_format?(name)\n  end\n\n  # @comment Document to_data_hash here as it is called as a hook from to_msgpack if it exists\n  # @!method to_data_hash(*args)\n  # @api public\n  # @abstract\n  # This method may be implemented to return a hash object that is used for serializing.\n  # The object returned by this method should contain all the info needed to instantiate it again.\n  # If the method exists it will be called from to_msgpack and other serialization methods.\n  # @return [Hash]\nend\n","sourceCodeStart":107,"sourceCodeEnd":141,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/network/format_support.rb#L107-L141","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing request-derived format names into mime(); typos in format names; pluginsync not delivering a custom format; version skew where a format was removed.","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."],"exampleFix":"# before\ncontent_type = obj.mime(params[:format]) # FormatError when unregistered\n\n# after\nknown = Widget.supported_formats.map(&:to_s)\nfmt = known.include?(params[:format]) ? params[:format] : nil # nil → default_format\ncontent_type = obj.mime(fmt)","handlingStrategy":"validation","validationCode":"known = Widget.supported_formats.map(&:to_s)\nfmt = known.include?(requested.to_s) ? requested : nil # nil arg → default_format\ncontent_type = widget.mime(fmt)","typeGuard":null,"tryCatchPattern":"begin\n  widget.mime(fmt)\nrescue Puppet::Network::FormatHandler::FormatError\n  widget.mime # the default format is always registered\nend","preventionTips":["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."],"tags":["puppet","ruby","serialization","formats","content-type"],"backgroundTag":"unsupported-content-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}