Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Faults faultT
Faults is the namespace for operating on faults.
Functions ¶
This section is empty.
Types ¶
type Descriptor ¶ added in v0.1.1
type Descriptor interface { // New creates a new instance of the fault. // // Returns: // - Fault: The new fault. Never returns nil. New() Fault fmt.Stringer }
Descriptor is the interface for a fault descriptor.
var ( // ErrPanic is the descriptor for a panic error. ErrPanic Descriptor // ErrNoSuchKey is the descriptor for a no such key error. ErrNoSuchKey Descriptor // ErrWrongKey is the descriptor for a wrong key error. ErrWrongKey Descriptor )
func FromErr ¶ added in v0.1.1
func FromErr[C Enum](code C, err error) Descriptor
FromErr creates a new Fault with the given code and the given error. If the error is nil, "something went wrong" is used.
Parameters:
- code: The code of the fault.
- err: The error to create the fault from.
Returns:
- Descriptor: The new fault.
func New ¶
func New[C Enum](code C, msg string) Descriptor
New creates a new Fault with the given message.
Parameters:
- code: The code of the fault.
- msg: The message of the fault.
Returns:
- Descriptor: The new fault. Never returns nil.
type Fault ¶
type Fault interface { // Error returns the message of the fault. // // Returns: // - string: The message of the fault. Error() string // Embeds returns the base of the fault. // // Returns: // - Fault: The base of the fault. Nil if the fault is the base. Embeds() Fault // Lines returns the info lines of the fault, if any. // // Returns: // - []string: The info lines of the fault. Lines() []string }
Fault is the interface for a fault.
func Get ¶ added in v0.1.1
Get returns the value associated with the given key in the context of the given fault, or a zero value of type T if the key is not in the context. If the fault is nil, or if the key is not in the context, then the second return value is nil. Otherwise, the second return value is the fault.
Returns:
- T: The value associated with the key, or a zero value of type T if the key is not in the context.
- Fault: The fault, or nil if the fault is nil or if the key is not in the context.
func NewErrNoSuchKey ¶ added in v0.1.1
NewErrNoSuchKey creates a new Fault indicating that a specified key does not exist.
Parameters:
- key: The key that was not found.
Returns:
- Fault: A Fault with context indicating the missing key.
func NewErrPanic ¶ added in v0.1.1
NewErrPanic creates a new Fault indicating a panic.
Parameters:
- value: The value of the panic.
Returns:
- Fault: A Fault with context indicating a panic.
func NewErrWrongKey ¶ added in v0.1.1
NewErrWrongKey creates a new Fault indicating that a specified key refers to a value of a different type.
Parameters:
- key: The key that was not found.
- expectedType: The expected type of the value.
- actualType: The actual type of the value.
Returns:
- Fault: A Fault with context indicating the wrong key.