RFC8785.EncodeError exception (rfc8785 v1.0.0)

Copy Markdown View Source

Raised when a term cannot be canonicalized per RFC 8785.

The message includes a JSONPath-style location (for example $.foo[3].bar) pointing at the offending value inside the input term.

:reason is a stable atom, so callers can branch on the cause without parsing prose; :message explains it and names the location.

case RFC8785.encode(term) do
  {:ok, json} -> json
  {:error, %RFC8785.EncodeError{reason: :integer_unrepresentable}} -> retry_as_string(term)
  {:error, error} -> {:rejected, error.message}
end

Summary

Types

Why the term was rejected

t()

Types

reason()

@type reason() ::
  :integer_unrepresentable
  | :duplicate_name
  | :invalid_key
  | :invalid_string
  | :unsupported_term
  | :improper_list

Why the term was rejected:

  • :integer_unrepresentable — an integer beyond ±2^53 whose decimal digits are not preserved by serialization through its nearest IEEE-754 double, or which is outside the double range entirely
  • :duplicate_name — a duplicate object name, as in %{:a => 1, "a" => 2} after the atom key is converted to a string
  • :invalid_key — an object key that is neither a string nor an atom
  • :invalid_string — a binary that is not valid UTF-8 or contains a Unicode noncharacter
  • :unsupported_term — a struct, tuple, or any other term with no JSON representation
  • :improper_list

t()

@type t() :: %RFC8785.EncodeError{
  __exception__: term(),
  message: String.t(),
  reason: reason()
}