Documentation
¶
Overview ¶
Package apperr is Gortexa's central error model. A single table of Mapping rows is the one source of truth that drives all three transports: gRPC status codes, HTTP status codes (for the grpc-gateway error handler), and MCP tool-call error envelopes. Domain code constructs *Error values with a Category; the adapters translate them per transport. A hard invariant holds everywhere: an Internal error (or any non-*Error) never serializes its underlying cause — only the category's SafeMessage is exposed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Default = NewRegistry(DefaultMappings()...)
Default is the process-wide registry seeded with DefaultMappings.
Functions ¶
func ToGRPCStatus ¶
Types ¶
type Category ¶
type Category string
Category is a transport-agnostic error class.
const ( CatInvalidArgument Category = "invalid_argument" CatUnauthenticated Category = "unauthenticated" CatPermissionDenied Category = "permission_denied" CatNotFound Category = "not_found" CatAlreadyExists Category = "already_exists" CatResourceExhausted Category = "resource_exhausted" CatFailedPrecondition Category = "failed_precondition" CatAborted Category = "aborted" CatDeadlineExceeded Category = "deadline_exceeded" CatUnimplemented Category = "unimplemented" CatInternal Category = "internal" CatCanceled Category = "canceled" CatOutOfRange Category = "out_of_range" CatDataLoss Category = "data_loss" )
type Error ¶
Error is a domain error carrying a Category, a client-safe message and an optional wrapped cause (never exposed for Internal).
func (*Error) GRPCStatus ¶
GRPCStatus lets *Error satisfy the gRPC status interface so handlers may return it directly. Uses the default registry.
type ErrorBody ¶
type ErrorBody struct {
Code string `json:"code"`
Message string `json:"message"`
RequestID string `json:"request_id,omitempty"`
}
ErrorBody is the JSON body emitted by the HTTP gateway error handler.
type MCPError ¶
type MCPError struct {
IsError bool `json:"isError"`
ErrorCategory string `json:"errorCategory"`
IsRetryable bool `json:"isRetryable"`
Message string `json:"message"`
}
MCPError is embedded in an MCP tools/call result on failure.
type Mapping ¶
type Mapping struct {
Category Category
GRPCCode codes.Code
HTTPStatus int
Retryable bool
SafeMessage string
}
Mapping is one row of the error table.
func DefaultMappings ¶
func DefaultMappings() []Mapping
DefaultMappings returns the seed error table.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps categories to transport codes. Safe for concurrent use.
func NewRegistry ¶
NewRegistry builds a registry seeded with the given mappings.
func (*Registry) Register ¶
Register adds a mapping, panicking (fail-loud at startup) on a duplicate category or a duplicate gRPC code. Code uniqueness matters because a pre-built gRPC status arriving over the loopback is resolved back to a category by its code (resolve's byCode passthrough); two categories sharing a code would make that reverse mapping ambiguous, so it is rejected at registration.
func (*Registry) ToGRPCStatus ¶
ToGRPCStatus maps any error to a gRPC status. A nil error maps to OK.