Urchin.Error exception (Urchin v0.1.0)

Copy Markdown View Source

JSON-RPC / MCP error representation.

An Urchin.Error is both a struct and an exception, so handlers may either return {:error, Urchin.Error.t()} or raise it. The dispatcher converts it into a JSON-RPC error object on the wire.

Summary

Functions

JSON-RPC invalid request (-32600): the payload is not a valid request object.

Code constant for method_not_found.

Builds an error with an explicit numeric code.

JSON-RPC parse error (-32700): invalid JSON was received.

Serializes the error into the JSON-RPC error object shape. The data member is omitted when nil.

Code constant for the URL-elicitation-required error.

Coerces an arbitrary value raised or returned by user code into an Urchin.Error.

Types

t()

@type t() :: %Urchin.Error{
  __exception__: true,
  code: integer(),
  data: term() | nil,
  message: String.t()
}

Functions

internal_error(message \\ "Internal error", data \\ nil)

@spec internal_error(String.t(), term() | nil) :: t()

JSON-RPC internal error (-32603).

invalid_params(message \\ "Invalid params", data \\ nil)

@spec invalid_params(String.t(), term() | nil) :: t()

JSON-RPC invalid params (-32602).

invalid_request(message \\ "Invalid Request", data \\ nil)

@spec invalid_request(String.t(), term() | nil) :: t()

JSON-RPC invalid request (-32600): the payload is not a valid request object.

method_not_found(message \\ "Method not found", data \\ nil)

@spec method_not_found(String.t(), term() | nil) :: t()

JSON-RPC method not found (-32601).

method_not_found_code()

@spec method_not_found_code() :: integer()

Code constant for method_not_found.

new(code, message, data \\ nil)

@spec new(integer(), String.t(), term() | nil) :: t()

Builds an error with an explicit numeric code.

parse_error(message \\ "Parse error", data \\ nil)

@spec parse_error(String.t(), term() | nil) :: t()

JSON-RPC parse error (-32700): invalid JSON was received.

to_map(error)

@spec to_map(t()) :: map()

Serializes the error into the JSON-RPC error object shape. The data member is omitted when nil.

url_elicitation_required_code()

@spec url_elicitation_required_code() :: integer()

Code constant for the URL-elicitation-required error.

wrap(error)

@spec wrap(term()) :: t()

Coerces an arbitrary value raised or returned by user code into an Urchin.Error.

Urchin.Error values pass through unchanged. Everything else becomes an internal error so that exceptions never leak transport details to the client.