Documentation
¶
Index ¶
- Variables
- func Fix(name string, obj Fixer, allow_nil bool) error
- func GetOrdinalSuffix(number int) string
- func LimitErrorMsg(err error, limit int) error
- type ErrAt
- type ErrEmpty
- type ErrFix
- type ErrGT
- type ErrGTE
- type ErrInvalidParameter
- type ErrInvalidUsage
- type ErrOutOfBounds
- type ErrValue
- type ErrValues
- type Fixer
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
var ( // NilValue is an error that is returned when a value is nil. NilValue error // NilReceiver is an error that is returned when a receiver is nil. NilReceiver error )
Functions ¶
func Fix ¶ added in v0.1.17
Fix fixes the object.
Parameters:
- name: The name of the object.
- obj: The object to fix.
- allow_nil: Whether to allow the object to be nil.
Returns:
- error: An error that occurred while fixing the object.
func GetOrdinalSuffix ¶ added in v0.1.6
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 LimitErrorMsg ¶ added in v0.1.11
LimitErrorMsg is a function that limits the number of errors in an error chain.
Parameters:
- err: The error to limit.
- limit: The maximum number of errors to limit.
Returns:
- error: The limited error.
If the error is nil or the limit is less than or equal to 0, the function returns nil.
Types ¶
type ErrAt ¶ added in v0.1.17
type ErrAt struct {
// Idx is the index of the error.
Idx int
// IdxType is the type of the index.
IdxType string
// Reason is the reason for the error.
Reason error
}
ErrAt represents an error that occurs at a specific index.
func NewErrAt ¶ added in v0.1.17
NewErrAt creates a new ErrAt error.
Parameters:
- idx: The index of the error.
- idx_type: The type of the index.
- reason: The reason for the error.
Returns:
- *ErrAt: A pointer to the newly created ErrAt. Never returns nil.
Empty name will default to "index".
func (*ErrAt) ChangeReason ¶ added in v0.1.17
ChangeReason implements the errors.Unwrapper interface.
type ErrEmpty ¶
type ErrEmpty struct {
// Type is the type of the empty value.
Type any
}
ErrEmpty represents an error when a value is empty.
func NewErrEmpty ¶
NewErrEmpty creates a new ErrEmpty error.
Parameters:
- var_type: The type of the empty value.
Returns:
- *ErrEmpty: A pointer to the newly created ErrEmpty. Never returns nil.
type ErrFix ¶ added in v0.1.17
type ErrFix struct {
// Name is the name of the object.
Name string
// Reason is the reason for the error.
Reason error
}
ErrFix is an error that is returned when an object cannot be fixed.
func NewErrFix ¶ added in v0.1.17
NewErrFix creates a new ErrFix error.
Parameters:
- name: the name of the object.
- reason: the reason for the error.
Returns:
- *ErrFix: the new error. Never returns nil.
func (*ErrFix) ChangeReason ¶ added in v0.1.17
ChangeReason changes the reason for the error.
Parameters:
- new_reason: the new reason for the error.
type ErrGT ¶ added in v0.1.2
ErrGT represents an error when a value is less than or equal to a specified value.
type ErrGTE ¶ added in v0.1.2
ErrGTE represents an error when a value is less than a specified value.
type ErrInvalidParameter ¶
type ErrInvalidParameter struct {
// Parameter is the name of the invalid parameter.
Parameter string
// Reason is the reason for the error.
Reason error
}
ErrInvalidParameter is an error that is returned when a parameter is invalid.
func NewErrInvalidParameter ¶
func NewErrInvalidParameter(parameter string, reason error) *ErrInvalidParameter
NewErrInvalidParameter creates a new ErrInvalidParameter error.
Parameters:
- parameter: the name of the invalid parameter.
- reason: the reason for the error.
Returns:
- *ErrInvalidParameter: the new error. Never returns nil.
func NewErrNilParameter ¶
func NewErrNilParameter(parameter string) *ErrInvalidParameter
NewErrNilParameter creates a new ErrInvalidParameter error.
Parameters:
- parameter: the name of the invalid parameter.
Returns:
- *ErrInvalidParameter: the new error. Never returns nil.
func (*ErrInvalidParameter) ChangeReason ¶
func (e *ErrInvalidParameter) ChangeReason(new_reason error)
ChangeReason changes the reason for the error.
Parameters:
- new_reason: the new reason for the error.
func (ErrInvalidParameter) Error ¶
func (e ErrInvalidParameter) Error() string
Error implements the error interface.
Message:
"parameter <parameter> is invalid: <reason>"
func (ErrInvalidParameter) Unwrap ¶
func (e ErrInvalidParameter) Unwrap() error
Unwrap implements the errors.Unwrap interface.
type ErrInvalidUsage ¶ added in v0.1.2
type ErrInvalidUsage struct {
// Reason is the reason for the invalid usage.
Reason error
// Usage is the usage of the function.
Usage string
}
ErrInvalidUsage represents an error that occurs when a function is used incorrectly.
func NewErrInvalidUsage ¶ added in v0.1.2
func NewErrInvalidUsage(reason error, usage string) *ErrInvalidUsage
NewErrInvalidUsage creates a new ErrInvalidUsage error.
Parameters:
- reason: The reason for the invalid usage.
- usage: The usage of the function.
Returns:
- *ErrInvalidUsage: A pointer to the new ErrInvalidUsage error.
func (*ErrInvalidUsage) ChangeReason ¶ added in v0.1.2
func (e *ErrInvalidUsage) ChangeReason(new_reason error)
ChangeReason implements the Unwrapper interface.
func (ErrInvalidUsage) Error ¶ added in v0.1.2
func (e ErrInvalidUsage) Error() string
Error is a method of the Unwrapper interface.
Message:
"{reason}. {usage}"
However, if the reason is nil, the message is "invalid usage. {usage}" instead.
If the usage is empty, no usage is added to the message.
func (ErrInvalidUsage) Unwrap ¶ added in v0.1.2
func (e ErrInvalidUsage) Unwrap() error
Unwrap implements the errors.Unwrap interface.
type ErrOutOfBounds ¶ added in v0.1.17
type ErrOutOfBounds struct {
// LowerBound is the lower bound of the value.
LowerBound int
// UpperBound is the upper bound of the value.
UpperBound int
// LowerInclusive is true if the lower bound is inclusive.
LowerInclusive bool
// UpperInclusive is true if the upper bound is inclusive.
UpperInclusive bool
// Value is the value that is out of bounds.
Value int
}
ErrOutOfBounds represents an error when a value is out of bounds.
func NewErrOutOfBounds ¶ added in v0.1.17
func NewErrOutOfBounds(value, lowerBound, upperBound int) *ErrOutOfBounds
NewErrOutOfBounds creates a new ErrOutOfBounds error.
Parameters:
- value: The value that is out of bounds.
- lowerBound: The lower bound of the value.
- upperBound: The upper bound of the value.
Returns:
- *ErrOutOfBounds: A pointer to the newly created ErrOutOfBounds. Never returns nil.
By default, the lower bound is inclusive and the upper bound is exclusive.
func (ErrOutOfBounds) Error ¶ added in v0.1.17
func (e ErrOutOfBounds) Error() string
Error implements the error interface.
Message: "value ( <value> ) not in range <lower_bound> , <upper_bound>"
func (*ErrOutOfBounds) WithLowerBound ¶ added in v0.1.17
func (e *ErrOutOfBounds) WithLowerBound(is_inclusive bool) *ErrOutOfBounds
WithLowerBound sets the lower bound of the value.
Parameters:
- is_inclusive: True if the lower bound is inclusive. False if the lower bound is exclusive.
Returns:
- *ErrOutOfBounds: A pointer to the newly created ErrOutOfBounds.
Only when the receiver is nil, this function returns nil.
func (*ErrOutOfBounds) WithUpperBound ¶ added in v0.1.17
func (e *ErrOutOfBounds) WithUpperBound(is_inclusive bool) *ErrOutOfBounds
WithUpperBound sets the upper bound of the value.
Parameters:
- is_inclusive: True if the upper bound is inclusive. False if the upper bound is exclusive.
Returns:
- *ErrOutOfBounds: A pointer to the newly created ErrOutOfBounds.
Only when the receiver is nil, this function returns nil.
type ErrValue ¶ added in v0.1.21
type ErrValue struct {
// Kind is the name of the thing that was expected.
Kind string
// Expected is the value that was expected.
Expected any
// Got is the value that was received.
Got any
// ShouldQuote is true if the expected and got values should be quoted,
// false otherwise.
ShouldQuote bool
}
ErrValue represents an error when a value is not expected.
func NewErrValue ¶ added in v0.1.21
NewErrValue creates a new ErrValue error.
Parameters:
- kind: The name of the thing that was expected.
- expected: The value that was expected.
- got: The value that was received.
- should_quote: True if the expected and got values should be quoted, false otherwise.
Returns:
- *ErrValue: A pointer to the newly created ErrValue. Never returns nil.
func NewErrValues ¶ added in v0.1.21
NewErrValues creates a new ErrValues error.
Parameters:
- kind: The name of the thing that was expected.
- expected: The values that were expected.
- got: The value that was received.
- should_quote: True if the expected and got values should be quoted, false otherwise.
Returns:
- *ErrValue: A pointer to the newly created ErrValue. Never returns nil.
type ErrValues ¶ added in v0.1.21
type ErrValues[T any] struct { // Kind is the name of the thing that was expected. Kind string // Expecteds is the values that were expected. Expecteds []T // Got is the value that was received. Got any // ShouldQuote is true if the expected and got values should be quoted, // false otherwise. ShouldQuote bool }
ErrValues represents an error when multiple value are not expected.
type Fixer ¶ added in v0.1.17
type Fixer interface {
// Fix fixes the object.
//
// Returns:
// - error: An error that occurred while fixing the object.
Fix() error
}
Fixer is defines the behavior of an object that can be fixed. This must not have a non-pointer receiver.
type Unwrapper ¶ added in v0.1.11
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.
ChangeReason(new_reason error)
}
Unwrapper is an interface that defines a method to unwrap an error.