Help us shape the future of Go! Take the 2026 Go Developer Survey

fault

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fault provides transport-independent, classifiable framework errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Attribute is a framework-owned, redaction-safe classification such as a PostgreSQL SQLSTATE or transport error code.

type Code

type Code string

Code classifies an error without requiring callers to inspect its message. Codes implement error so errors.Is(err, fault.Invalid) is supported.

const (
	Invalid   Code = "invalid"
	Duplicate Code = "duplicate"
	Missing   Code = "missing"
	Cycle     Code = "cycle"
	Closed    Code = "closed"
	Conflict  Code = "conflict"
	Internal  Code = "internal"
	Panicked  Code = "panicked"
	Timeout   Code = "timeout"
	// Overloaded reports temporarily exhausted concurrency or queue capacity.
	// The operation was not started; the same request may be retried later.
	// Transports map it to "service unavailable" rather than an internal error.
	Overloaded Code = "overloaded"
)

func (Code) Error

func (c Code) Error() string

Error returns the fault code as an error message.

type Diagnostic

type Diagnostic struct {
	Types      []string    `json:"types,omitempty"`
	Faults     []Note      `json:"faults,omitempty"`
	Attributes []Attribute `json:"attributes,omitempty"`
	Frames     []Frame     `json:"frames,omitempty"`
	// Truncated reports that bounds or a failing error method ended inspection.
	Truncated bool `json:"truncated,omitempty"`
}

Diagnostic is a bounded, redacted failure summary that is safe to log and to export to error reporters. It contains dynamic Go type names, framework fault notes, framework attributes and contained-panic frames. It never contains arbitrary Error() text, payloads, credentials or recovered panic values.

func (Diagnostic) Clone

func (d Diagnostic) Clone() Diagnostic

Clone returns an owned copy whose slices do not alias d.

func (Diagnostic) IsZero

func (d Diagnostic) IsZero() bool

IsZero reports whether no failure information was captured.

func (Diagnostic) LogValue

func (d Diagnostic) LogValue() slog.Value

LogValue renders the diagnostic as a structured slog group.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error retains an internal cause while exposing only its explicit safe message through formatting. Causes remain available through errors.Is/errors.As.

func New

func New(code Code, message string) *Error

New constructs an error with a safe diagnostic message.

func Panic

func Panic(message string, frames []Frame) *Error

Panic constructs a Panicked fault retaining where the contained panic began. Frames carry source locations only, never argument values or the panic value.

func Wrap

func Wrap(code Code, message string, cause error) *Error

Wrap adds classification and a safe message without formatting the cause.

func (*Error) Code

func (e *Error) Code() Code

Code returns the error's fault code.

func (*Error) Error

func (e *Error) Error() string

Error returns the fault code and message.

func (*Error) Frames

func (e *Error) Frames() []Frame

Frames returns an owned copy of a contained panic's source locations.

func (*Error) GoString

func (e *Error) GoString() string

GoString returns the same text as Error.

func (*Error) Is

func (e *Error) Is(target error) bool

Is reports whether the target fault code equals this error's code.

func (*Error) Message

func (e *Error) Message() string

Message returns the error's message.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying cause.

type Frame

type Frame struct {
	Function string `json:"function"`
	File     string `json:"file"`
	Line     int    `json:"line"`
}

Frame is one source location of a contained panic. It never carries argument values, locals or the recovered panic value.

func (Frame) String

func (f Frame) String() string

String returns the function name and file location.

type Note

type Note struct {
	Code    Code   `json:"code"`
	Message string `json:"message"`
}

Note is one framework fault found in a failure's error graph. Messages come from framework-owned fault constructors, which never format causes.

Jump to

Keyboard shortcuts

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