Documentation
¶
Overview ¶
Package fault is the shared error taxonomy for the funcd platform (ADR-0002). It is stdlib-only and imported "up" by internal/** and pkg/**; it imports nothing beyond the standard library. Every layer builds errors from this package; the API edge maps them to RFC 9457 application/problem+json.
Index ¶
- func LogCause(w http.ResponseWriter, err error)
- func LogCauses(logger *slog.Logger) func(http.Handler) http.Handler
- func StatusOf(err error) int
- func WriteProblem(w http.ResponseWriter, err error)
- type Error
- func Conflictf(op, format string, a ...any) *Error
- func DeadlineExceededf(op, format string, a ...any) *Error
- func Forbiddenf(op, format string, a ...any) *Error
- func InsufficientStoragef(op, format string, a ...any) *Error
- func Internalf(op, format string, a ...any) *Error
- func Invalidf(op, format string, a ...any) *Error
- func NotFoundf(op, format string, a ...any) *Error
- func PayloadTooLargef(op, format string, a ...any) *Error
- func ResourceExhaustedf(op, format string, a ...any) *Error
- func Unauthorizedf(op, format string, a ...any) *Error
- func Unavailablef(op, format string, a ...any) *Error
- func Wrapf(err error, k Kind, op, format string, a ...any) *Error
- type Kind
- type Problem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogCause ¶ added in v0.38.0
func LogCause(w http.ResponseWriter, err error)
LogCause logs err through the logger LogCauses put on w when err's problem detail leaves part of it out: a 500 at Error, any other status at Warn. WriteProblem calls it, and so does a transport that renders ToProblem itself (ADR-0005 §4). Without LogCauses it does nothing: a handler outside it logs what it is handed before it answers.
func LogCauses ¶ added in v0.38.0
LogCauses is the middleware of an HTTP operation's owner, which logs a failure once (ADR-0002 §3): through logger, it logs the error behind each problem whose detail leaves part of it out. It sits inside every other ResponseWriter wrapper, because LogCause finds it on the writer the handler holds.
func WriteProblem ¶
func WriteProblem(w http.ResponseWriter, err error)
WriteProblem writes an error as an RFC 9457 application/problem+json response. It sets Content-Type and writes the JSON body.
Types ¶
type Error ¶
type Error struct {
Kind Kind
Op string // e.g. "store.Get", "blob.Put" — free string, open set
Msg string // human-readable, safe to surface to callers
Detail map[string]string // deliberately flat, key-value diagnostic pairs
Err error // wrapped cause
}
Error is the typed error used throughout the platform. It carries a Kind (for HTTP mapping), an Op (free string describing the operation that failed), a human-readable Msg, optional flat Detail (key-value pairs), and the wrapped cause via Err.
func DeadlineExceededf ¶ added in v0.4.0
DeadlineExceededf builds a DeadlineExceeded error (504) with a formatted message.
func Forbiddenf ¶
Forbiddenf builds a Forbidden error with a formatted message.
func InsufficientStoragef ¶ added in v0.33.0
InsufficientStoragef builds an InsufficientStorage error (507) with a formatted message.
func PayloadTooLargef ¶
PayloadTooLargef builds a PayloadTooLarge error (413) with a formatted message.
func ResourceExhaustedf ¶
ResourceExhaustedf builds a ResourceExhausted error (429) with a formatted message.
func Unauthorizedf ¶
Unauthorizedf builds an Unauthorized error with a formatted message.
func Unavailablef ¶
Unavailablef builds an Unavailable error with a formatted message.
type Kind ¶
type Kind string
Kind is the machine-readable error kind — the stable identifier that maps to HTTP status codes and problem+json type URIs. Kinds are an open set but the enumerated constants below cover every case the platform needs.
const ( // Invalid means the request is malformed or a required dependency is missing. Invalid Kind = "invalid" // NotFound means the requested resource does not exist. NotFound Kind = "not_found" // Conflict means the request conflicts with the current state (e.g. duplicate name). Conflict Kind = "conflict" Unauthorized Kind = "unauthorized" // Forbidden means the authenticated identity lacks permission. Forbidden Kind = "forbidden" Unavailable Kind = "unavailable" // ResourceExhausted means a rate/quota limit was exceeded (429 Too Many Requests). ResourceExhausted Kind = "resource_exhausted" // PayloadTooLarge means a payload, key, object or record is over a size cap funcd enforces (413 // Content Too Large when it answers HTTP). PayloadTooLarge Kind = "payload_too_large" // InsufficientStorage means a write would take a store past its quota (507 Insufficient Storage, ADR-0292). InsufficientStorage Kind = "insufficient_storage" // DeadlineExceeded means the upstream did not start its response in time (504 Gateway Timeout, ADR-0151). DeadlineExceeded Kind = "deadline_exceeded" // Internal means an unexpected internal error occurred. Internal Kind = "internal" )