Documentation ¶
Index ¶
- Constants
- func Error(err error) string
- func GetOrdinalSuffix(number int) string
- func Got(quote bool, got any) string
- func Is[T error](err error) bool
- func LimitErrorMsg(err error, limit int) error
- func StringOfSlice[T any](quoted bool, elems []T) []string
- type Enumer
- type Err
- type ErrAfter
- type ErrAssertFailed
- type ErrBefore
- type ErrInvalidCall
- type ErrLT
- type ErrLTE
- type ErrOrSol
- func (e *ErrOrSol[T]) AddAny(elem any, level int) bool
- func (e *ErrOrSol[T]) AddErr(err error, level int) bool
- func (e *ErrOrSol[T]) AddSol(sol T, level int) bool
- func (e ErrOrSol[T]) Errors() []error
- func (e ErrOrSol[T]) HasError() bool
- func (e *ErrOrSol[T]) Reset()
- func (e ErrOrSol[T]) Solutions() []T
- type ErrPanic
- type ErrUnexpected
- type ErrUnexpectedType
- type ErrUnexpectedValue
- type ErrWhile
- type Unwrapper
Constants ¶
const AssertionFailed string = "[ASSERTION FAILED]: "
AssertionFailed is the message that is shown when an assertion fails.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
Error returns the error message of an error.
Parameters:
- err: The error to get the message of.
Returns:
- string: The error message of the error.
If the error is nil, the function returns "something went wrong" as the error message.
func GetOrdinalSuffix ¶
GetOrdinalSuffix returns the ordinal suffix for a given integer.
Parameters:
- number: The integer for which to get the ordinal suffix. Negative numbers are treated as positive.
Returns:
- string: The ordinal suffix for the number.
Example:
- GetOrdinalSuffix(1) returns "1st"
- GetOrdinalSuffix(2) returns "2nd"
func Got ¶
Got returns the string representation of a value.
Parameters:
- quote: A flag indicating whether the value should be quoted.
- got: The value to get the string representation of.
Returns:
- string: The string "got <value> instead"
If the value is nil, the function returns "got nothing instead" regardless of the flag.
func Is ¶
Is is function that checks if an error is of type T.
Parameters:
- err: The error to check.
Returns:
- bool: true if the error is of type T, false otherwise (including if the error is nil).
func LimitErrorMsg ¶
LimitErrorMsg limits the error message to a certain number of unwraps. It returns the top level error for allowing to print the error message with the limit of unwraps applied.
If the error is nil or the limit is less than 0, the function does nothing.
Parameters:
- err: The error to limit.
- limit: The limit of unwraps.
Returns:
- error: The top level error with the limit of unwraps applied.
func StringOfSlice ¶
StringOfSlice returns the string representation of a slice of values.
Parameters:
- quoted: A flag indicating whether the values should be quoted.
- elems: The slice of values to get the string representation of.
Returns:
- []string: The string representation of the slice of values.
Types ¶
type Enumer ¶
type Enumer interface { ~int // String returns the literal name of the enum. // // Returns: // - string: The name of the enum. String() string }
Enumer is an enum type.
type Err ¶
type Err[T Enumer] struct { // Code is the error code. Code T // Message is the error message. Message error // Suggestions are the error suggestions. Suggestions []string }
Err is the base error type.
func NewErr ¶
NewErr creates a new error.
Parameters:
- code: The error code.
- message: The error message.
Returns:
- *Err: The new error. Never returns nil.
func (*Err[T]) AddSuggestion ¶
AddSuggestion adds a suggestion of the error.
Parameters:
- suggestions: The suggestion of the error.
Returns:
- *Err: The error. Never returns nil.
Each element in the suggestion is separated by a space but each call to this function adds each suggestion on a new line.
func (*Err[T]) ChangeReason ¶
ChangeReason implements the Unwrapper interface.
type ErrAfter ¶
type ErrAfter struct { // After is the element that was processed before the error occurred. After string // Reason is the reason for the error. Reason error }
ErrAfter is an error that is returned when something goes wrong after a certain element in a stream of data.
func NewErrAfter ¶
NewErrAfter creates a new ErrAfter error.
Parameters:
- after: The element that was processed before the error occurred.
- reason: The reason for the error.
Returns:
- *ErrAfter: A pointer to the new ErrAfter error. Never returns nil.
func (*ErrAfter) ChangeReason ¶
ChangeReason implements the Unwrapper interface.
type ErrAssertFailed ¶
type ErrAssertFailed struct { // Msg is the message that is shown when the assertion fails. Msg string }
ErrAssertFailed is the error that is shown when an assertion fails.
func NewErrAssertFailed ¶
func NewErrAssertFailed(msg string) *ErrAssertFailed
NewErrAssertFailed is a constructor for ErrAssertFailed.
Parameters:
- msg: the message that is shown when the assertion fails.
Returns:
- *ErrAssertFailed: the error. Never returns nil.
func (ErrAssertFailed) Error ¶
func (e ErrAssertFailed) Error() string
Error implements the error interface.
Message: "[ASSERTION FAILED]: <msg>"
type ErrBefore ¶
type ErrBefore struct { // Before is the element that was processed before the error occurred. Before string // Reason is the reason for the error. Reason error }
ErrBefore is an error that is returned when something goes wrong before a certain element in a stream of data.
func NewErrBefore ¶
NewErrBefore creates a new ErrBefore error.
Parameters:
- before: The element that was processed before the error occurred.
- reason: The reason for the error.
Returns:
- *ErrBefore: A pointer to the new ErrBefore error. Never returns nil.
func (*ErrBefore) ChangeReason ¶
ChangeReason implements the Unwrapper interface.
type ErrInvalidCall ¶
type ErrInvalidCall struct { // FnName is the name of the function. FnName string // Signature is the Signature of the function. Signature reflect.Type // Reason is the Reason for the failure. Reason error }
ErrInvalidCall represents an error that occurs when a function is not called correctly.
func NewErrInvalidCall ¶
func NewErrInvalidCall(functionName string, function any, reason error) *ErrInvalidCall
NewErrInvalidCall creates a new ErrInvalidCall.
Parameters:
- functionName: The name of the function.
- function: The function that failed.
- reason: The reason for the failure.
Returns:
- *ErrInvalidCall: A pointer to the new ErrInvalidCall. Never returns nil.
func (*ErrInvalidCall) ChangeReason ¶
func (e *ErrInvalidCall) ChangeReason(reason error) bool
ChangeReason implements the Unwrapper interface.
func (ErrInvalidCall) Error ¶
func (e ErrInvalidCall) Error() string
Error implements the Unwrapper interface.
Message: "call to {function}({signature}) failed: {reason}".
However, if the reason is nil, the message is "call to {function}({signature}) failed" instead.
func (*ErrInvalidCall) Unwrap ¶
func (e *ErrInvalidCall) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrLT ¶
ErrLT represents an error when a value is greater than or equal to a specified value.
type ErrLTE ¶
ErrLTE represents an error when a value is greater than a specified value.
type ErrOrSol ¶
type ErrOrSol[T any] struct { // contains filtered or unexported fields }
ErrOrSol is a struct that holds a list of errors and a list of solutions.
func (*ErrOrSol[T]) AddAny ¶
AddAny adds an element to the list of errors or solutions if the level is greater or equal to the current level.
Parameters:
- elem: The element to add.
- level: The level of the element.
Returns:
- bool: True if the receiver is not nil, false otherwise.
Behaviors:
- If an error has been added with a level greater than the current level, the error list is reset and the new level is updated.
- If a solution has been added with a level greater than the current level, the solution list is reset and the new level is updated.
func (*ErrOrSol[T]) AddErr ¶
AddErr adds an error to the list of errors if the level is greater or equal to the current level. Nil errors are ignored.
Parameters:
- err: The error to add.
- level: The level of the error.
Returns:
- bool: True if the receiver is not nil, false otherwise.
Behaviors:
- If an error has been added with a level greater than the current level, the error list is reset and the new level is updated.
- If the error is nil, the ignoreErr flag is set to true and the error list is reset.
func (*ErrOrSol[T]) AddSol ¶
AddSol adds a solution to the list of solutions if the level is greater or equal to the current level.
Parameters:
- sol: The solution to add.
- level: The level of the solution.
Returns:
- bool: True if the receiver is not nil, false otherwise.
Behaviors:
- If a solution has been added with a level greater than the current level, the solution list is reset and the new level is updated.
- This function sets the ignoreErr flag to true and resets the error list.
func (ErrOrSol[T]) Errors ¶
Errors returns the list of errors. It is a copy of the error list.
Returns:
- []error: The list of errors.
func (ErrOrSol[T]) HasError ¶
HasError checks if errors are not ignored and if the error list is not empty.
Returns:
- bool: True if errors are not ignored and the error list is not empty, otherwise false.
type ErrPanic ¶
type ErrPanic struct { // Value is the value that caused the panic. Value any }
ErrPanic represents an error when a panic occurs.
func NewErrPanic ¶
NewErrPanic creates a new ErrPanic error.
Parameters:
- value: The value that caused the panic.
Returns:
- *ErrPanic: A pointer to the newly created ErrPanic. Never returns nil.
type ErrUnexpected ¶
type ErrUnexpected[T any] struct { // Expecteds is the list of expected values. Expecteds []T // Got is the unexpected value. Got any // Quoted is a flag indicating whether values should be quoted. Quoted bool // Kind is the kind of the unexpected value. Kind string }
ErrUnexpected represents an error when an unexpected value is encountered.
func NewErrUnexpected ¶
func NewErrUnexpected[T any](quoted bool, expecteds []T, kind string, got any) *ErrUnexpected[T]
NewErrUnexpected creates a new ErrUnexpected error with the specified values.
Parameters:
- quoted: A flag indicating whether values should be quoted.
- expecteds: The list of expected values.
- kind: The kind of the unexpected value.
- got: The unexpected value.
Returns:
- *ErrUnexpected: A pointer to the newly created ErrUnexpected. Never returns nil.
func (ErrUnexpected[T]) Error ¶
func (e ErrUnexpected[T]) Error() string
Error implements the error interface.
Message: "expected <expecteds> <kind>, got <got> instead"
type ErrUnexpectedType ¶
type ErrUnexpectedType[T any] struct { // Elem is the element that caused the error. Elem T // Kind is the category of the type that was expected. Kind string }
ErrUnexpectedType represents an error when a value has an invalid type.
func NewErrUnexpectedType ¶
func NewErrUnexpectedType[T any](kind string, elem T) *ErrUnexpectedType[T]
NewErrUnexpectedType creates a new ErrUnexpectedType error.
Parameters:
- kind: The name of the type that was expected.
- elem: The element that caused the error.
Returns:
- *ErrUnexpectedType: A pointer to the newly created ErrUnexpectedType. Never returns nil.
func (ErrUnexpectedType[T]) Error ¶
func (e ErrUnexpectedType[T]) Error() string
Error implements the error interface.
Message: "type <type> is not a valid <kind> type"
type ErrUnexpectedValue ¶
type ErrUnexpectedValue[T fmt.Stringer] struct { // Elem is the element that caused the error. Elem T // Kind is the category of the type that was expected. Kind string }
ErrUnexpectedValue represents an error when an unexpected value is encountered. This is mostly used in the 'default' case of switch statements.
func NewErrUnexpectedValue ¶
func NewErrUnexpectedValue[T fmt.Stringer](elem T, kind string) *ErrUnexpectedValue[T]
NewErrUnexpectedValue creates a new ErrUnexpectedValue error.
Parameters:
- elem: The element that caused the error.
- kind: The name of the type that was expected.
Returns:
- *ErrUnexpectedValue: A pointer to the newly created ErrUnexpectedValue. Never returns nil.
func (ErrUnexpectedValue[T]) Error ¶
func (e ErrUnexpectedValue[T]) Error() string
Error implements the error interface.
Message: "<type> (<elem>) is not a supported <kind> type"
type ErrWhile ¶
type ErrWhile struct { // Operation is the operation that was being performed. Operation string // Reason is the reason for the error. Reason error }
ErrWhile represents an error that occurs while performing an operation.
func NewErrWhile ¶
NewErrWhile creates a new ErrWhile error.
Parameters:
- operation: The operation that was being performed.
- reason: The reason for the error.
Returns:
- *ErrWhile: A pointer to the newly created ErrWhile.
func (*ErrWhile) ChangeReason ¶
ChangeReason implements the Unwrapper interface.
type Unwrapper ¶
type Unwrapper interface { // Unwrap returns the error that this error wraps. // // Returns: // - error: The error that this error wraps. Unwrap() error // ChangeReason changes the reason of the error. // // Parameters: // - reason: The new reason of the error. // // Returns: // - bool: True if the receiver is not nil, false otherwise. ChangeReason(reason error) bool }
Unwrapper is an interface that defines a method to unwrap an error.