fault

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

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 Conflictf

func Conflictf(op, format string, a ...any) *Error

Conflictf builds a Conflict error with a formatted message.

func DeadlineExceededf added in v0.4.0

func DeadlineExceededf(op, format string, a ...any) *Error

DeadlineExceededf builds a DeadlineExceeded error (504) with a formatted message.

func Forbiddenf

func Forbiddenf(op, format string, a ...any) *Error

Forbiddenf builds a Forbidden error with a formatted message.

func Internalf

func Internalf(op, format string, a ...any) *Error

Internalf builds an Internal error with a formatted message.

func Invalidf

func Invalidf(op, format string, a ...any) *Error

Invalidf builds an Invalid error with a formatted message.

func NotFoundf

func NotFoundf(op, format string, a ...any) *Error

NotFoundf builds a NotFound error with a formatted message.

func PayloadTooLargef

func PayloadTooLargef(op, format string, a ...any) *Error

PayloadTooLargef builds a PayloadTooLarge error (413) with a formatted message.

func ResourceExhaustedf

func ResourceExhaustedf(op, format string, a ...any) *Error

ResourceExhaustedf builds a ResourceExhausted error (429) with a formatted message.

func Unauthorizedf

func Unauthorizedf(op, format string, a ...any) *Error

Unauthorizedf builds an Unauthorized error with a formatted message.

func Unavailablef

func Unavailablef(op, format string, a ...any) *Error

Unavailablef builds an Unavailable error with a formatted message.

func Wrapf

func Wrapf(err error, k Kind, op, format string, a ...any) *Error

Wrapf wraps an existing error with a Kind, Op, and formatted message. It is the primary tool for annotating errors as they propagate up through layers.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped cause, enabling errors.As and errors.Is traversal.

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 means authentication is required but was not provided or is invalid.
	Unauthorized Kind = "unauthorized"
	// Forbidden means the authenticated identity lacks permission.
	Forbidden Kind = "forbidden"
	// Unavailable means the service is temporarily unable to handle the request.
	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"
	// 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"
)

func KindOf

func KindOf(err error) Kind

KindOf walks the error chain via errors.As and returns the first Kind found. If no Kind is found it returns Internal — unknown errors are internal faults.

type Problem

type Problem struct {
	Type     string `json:"type"`
	Title    string `json:"title"`
	Status   int    `json:"status"`
	Detail   string `json:"detail"`
	Instance string `json:"instance,omitempty"`
}

Problem is an RFC 9457 application/problem+json body.

func ToProblem

func ToProblem(err error) Problem

ToProblem maps an error to an RFC 9457 Problem using KindOf to select the type URI and status. This is the single site where HTTP status codes are decided for the platform.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL