Builds the error document Lambda expects on /runtime/invocation/<id>/error
and /runtime/init/error:
%{errorType: "KeyError", errorMessage: "key :a not found", stackTrace: [...]}Error types
- Exceptions raised by a handler use their module name
(
"KeyError","MyApp.ValidationError"). {:error, reason}returned by a handler is"HandlerError", unlessreasonis already a map witherrorType/errorMessage(atom or string keys), which is passed through so handlers can emit structured errors.exit/1andthrow/1become"Exit"and"Throw".- Runtime-detected problems use
Runtime.*types (Runtime.InvalidResponse,Runtime.NoSuchHandler, ...).
Header type
Lambda classifies errors by the Lambda-Runtime-Function-Error-Type header
and normalises anything not shaped like <Category.Reason> (Category being
Runtime or Function) to Runtime.Unknown/Function.Unknown.
header_type/1 derives a conforming value: Runtime.* is kept as is, every
other type is prefixed with Function. and stripped of dots.
Whatever a handler returns in {:error, reason} ends up in the payload,
which API Gateway may forward to clients. Terms are rendered with a bounded
inspect/2.
Summary
Functions
Formats a stacktrace as a list of lines, dropping frames that belong to Mayfly itself so the handler's frames come first.
Builds a payload from a value caught with catch kind, reason.
Builds a payload from an exception, a handler {:error, reason} value or any term.
Value for the Lambda-Runtime-Function-Error-Type header.
Builds a runtime error payload with an explicit Runtime.* type.
X-Ray cause document (Lambda-Runtime-Function-Xray-Error-Cause).
Types
Functions
@spec format_stacktrace(Exception.stacktrace() | nil) :: [String.t()]
Formats a stacktrace as a list of lines, dropping frames that belong to Mayfly itself so the handler's frames come first.
@spec from_caught(:exit | :throw | :error, term(), Exception.stacktrace() | nil) :: t()
Builds a payload from a value caught with catch kind, reason.
@spec from_term(term(), Exception.stacktrace() | nil) :: t()
Builds a payload from an exception, a handler {:error, reason} value or any term.
Value for the Lambda-Runtime-Function-Error-Type header.
iex> Mayfly.ErrorPayload.header_type("Runtime.InvalidResponse")
"Runtime.InvalidResponse"
iex> Mayfly.ErrorPayload.header_type("MyApp.Validation.Error")
"Function.MyAppValidationError"
iex> Mayfly.ErrorPayload.header_type("HandlerError")
"Function.HandlerError"
Builds a runtime error payload with an explicit Runtime.* type.
X-Ray cause document (Lambda-Runtime-Function-Xray-Error-Cause).