A2A.JSONRPC.Error (A2A v0.3.0)

Copy Markdown View Source

JSON-RPC 2.0 error with A2A-specific error codes.

Provides a struct and named constructors for the 14 error codes defined by the A2A protocol (5 standard JSON-RPC + 9 A2A-specific).

A2A-specific errors (-32001..-32009) serialize with a google.rpc.ErrorInfo object inside a "data" array, as the spec requires. The 5 standard JSON-RPC codes have no defined reason and keep their free-form data.

Example

iex> error = A2A.JSONRPC.Error.task_not_found()
iex> error.code
-32001
iex> A2A.JSONRPC.Error.to_map(error)
%{
  "code" => -32001,
  "message" => "Task not found",
  "data" => [
    %{
      "@type" => "type.googleapis.com/google.rpc.ErrorInfo",
      "domain" => "a2a-protocol.org",
      "reason" => "TASK_NOT_FOUND"
    }
  ]
}

Summary

Functions

Builds an authenticated extended card not configured error (-32007).

Builds a content type not supported error (-32005).

Builds an extension support required error (-32008).

Builds an internal error (-32603).

Builds an invalid agent response error (-32006).

Builds an invalid params error (-32602).

Builds an invalid request error (-32600).

Builds a method not found error (-32601).

Builds a parse error (-32700).

Builds a push notification not supported error (-32003).

Builds a task not cancelable error (-32002).

Builds a task not found error (-32001).

Converts an error struct to a JSON-ready map.

Builds an unsupported operation error (-32004).

Builds a version not supported error (-32009).

Types

t()

@type t() :: %A2A.JSONRPC.Error{code: integer(), data: term(), message: String.t()}

Functions

authenticated_extended_card_not_configured(data \\ nil)

@spec authenticated_extended_card_not_configured(term()) :: t()

Builds an authenticated extended card not configured error (-32007).

content_type_not_supported(data \\ nil)

@spec content_type_not_supported(term()) :: t()

Builds a content type not supported error (-32005).

extension_support_required(data \\ nil)

@spec extension_support_required(term()) :: t()

Builds an extension support required error (-32008).

internal_error(data \\ nil)

@spec internal_error(term()) :: t()

Builds an internal error (-32603).

invalid_agent_response(data \\ nil)

@spec invalid_agent_response(term()) :: t()

Builds an invalid agent response error (-32006).

invalid_params(data \\ nil)

@spec invalid_params(term()) :: t()

Builds an invalid params error (-32602).

invalid_request(data \\ nil)

@spec invalid_request(term()) :: t()

Builds an invalid request error (-32600).

method_not_found(data \\ nil)

@spec method_not_found(term()) :: t()

Builds a method not found error (-32601).

parse_error(data \\ nil)

@spec parse_error(term()) :: t()

Builds a parse error (-32700).

push_notification_not_supported(data \\ nil)

@spec push_notification_not_supported(term()) :: t()

Builds a push notification not supported error (-32003).

task_not_cancelable(data \\ nil)

@spec task_not_cancelable(term()) :: t()

Builds a task not cancelable error (-32002).

task_not_found(data \\ nil)

@spec task_not_found(term()) :: t()

Builds a task not found error (-32001).

to_map(error)

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

Converts an error struct to a JSON-ready map.

For A2A-specific codes (-32001..-32009) "data" is always an array carrying a google.rpc.ErrorInfo object; any free-form data is preserved under its "metadata". For standard JSON-RPC codes "data" is passed through as-is and omitted when nil.

iex> error = A2A.JSONRPC.Error.internal_error("boom")
iex> A2A.JSONRPC.Error.to_map(error)
%{"code" => -32603, "message" => "Internal error", "data" => "boom"}

unsupported_operation(data \\ nil)

@spec unsupported_operation(term()) :: t()

Builds an unsupported operation error (-32004).

version_not_supported(data \\ nil)

@spec version_not_supported(term()) :: t()

Builds a version not supported error (-32009).