Documentation
¶
Index ¶
- func As(err error) (*gcers.Err, bool)
- func AsWithCode[T gcers.ErrorCoder](err error, code T) (*gcers.Err, bool)
- func Assert(cond bool, msg string)
- func AssertConv[T any](obj any, name string) T
- func AssertErr(err error, format string, args ...any)
- func AssertF(cond bool, format string, args ...any)
- func AssertNotNil(obj any, name string)
- func AssertNotOk(ok bool, format string, args ...any)
- func AssertNotZero[T comparable](obj T, name string)
- func AssertOk(ok bool, format string, args ...any)
- func AssertType[T any](obj any, name string, allow_nil bool)
- func Fix(name string, obj Fixer, allow_nil bool) error
- func Is[T gcers.ErrorCoder](err error, code T) bool
- func NewErrAfter(before string, reason error) *gcers.Err
- func NewErrAssertFail(msg string) *gcers.Err
- func NewErrAt(at string, reason error) *gcers.Err
- func NewErrBefore(after string, reason error) *gcers.Err
- func NewErrFix(message string, reason error) *gcers.Err
- func NewErrInvalidParameter(message string) *gcers.Err
- func NewErrInvalidUsage(message string, usage string) *gcers.Err
- func NewErrNilParameter(parameter string) *gcers.Err
- func NewErrNoSuchKey(key string) *gcers.Err
- func Value[C gcers.ErrorCoder, T any](e *gcers.Err, key string) (T, error)
- func ZeroOf[T any]() T
- type ErrorCode
- type Fixer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As returns the error if it is of type T.
Parameters:
- err: The error to check.
- code: The error code to check.
Returns:
- *gcers.Err: The error if it is of type T, nil otherwise.
- bool: true if the error is of type T, false otherwise (including if the error is nil).
func AsWithCode ¶
AsWithCode returns the error if it is of type T.
Parameters:
- err: The error to check.
- code: The error code to check.
Returns:
- *gcers.Err: The error if it is of type T, nil otherwise.
- bool: true if the error is of type T, false otherwise (including if the error is nil).
func Assert ¶
Assert asserts that a condition is true.
If the condition is false, it calls panic() with an error.Err with the code AssertFail and the given message.
Parameters:
- cond: The condition to assert.
- msg: The message to use if the condition is false.
func AssertConv ¶
AssertConv asserts that the given object can be converted to type T.
If the object can be converted to type T, it returns the converted value. Otherwise, it calls panic() with an error.Err with the code AssertFail and a message that includes the original object and its expected type.
Parameters:
- obj: The object to convert to type T.
- name: The name of the object to use for the error message.
Returns:
- T: The converted value.
func AssertErr ¶
AssertErr asserts that an error is nil.
If the error is not nil, it calls panic() with an error.Err with the code AssertFail and a message that includes the original error.
Parameters:
- err: The error to check.
- format: The format string to use for the message.
- args: The arguments to pass to the format string.
func AssertF ¶
AssertF asserts that a condition is true.
If the condition is false, it calls panic() with an error.Err with the code AssertFail and a message that includes the formatted string.
Parameters:
- cond: The condition to assert.
- format: The format string to use for the message.
- args: The arguments to pass to the format string.
func AssertNotNil ¶
AssertNotNil asserts that the given object is not nil.
If the object is nil, it calls panic() with an error.Err with the code AssertFail and a message that includes the original object.
Parameters:
- obj: The object to assert is not nil.
- name: The name of the object to use for the error message.
func AssertNotOk ¶
AssertNotOk asserts that a condition is false.
If the condition is true, it calls panic() with an error.Err with the code AssertFail and a message that includes the original condition.
Parameters:
- ok: The condition to assert.
- format: The format string to use for the message.
- args: The arguments to pass to the format string.
func AssertNotZero ¶
func AssertNotZero[T comparable](obj T, name string)
AssertNotZero asserts that the given object is not its zero value.
If the object is its zero value, it calls panic() with an error.Err with the code AssertFail and a message that includes the original object and its zero value.
Parameters:
- obj: The object to assert is not its zero value.
- name: The name of the object to use for the error message.
func AssertOk ¶
AssertOk asserts that a condition is true.
If the condition is false, it calls panic() with an error.Err with the code AssertFail and a message that includes the original condition.
Parameters:
- ok: The condition to assert.
- format: The format string to use for the message.
- args: The arguments to pass to the format string.
func AssertType ¶
AssertType asserts that the given object is of type T.
If the object is not of type T, it calls panic() with an error.Err with the code AssertFail and a message that includes the original object and its expected type.
Parameters:
- obj: The object to assert is of type T.
- name: The name of the object to use for the error message.
- allow_nil: Whether to allow the object to be nil.
func Fix ¶
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 Is ¶
func Is[T gcers.ErrorCoder](err error, code T) bool
Is is function that checks if an error is of type T.
Parameters:
- err: The error to check.
- code: The error code to check.
Returns:
- bool: true if the error is of type T, false otherwise (including if the error is nil).
func NewErrAfter ¶
NewErrAfter creates a new error.Err error.
Parameters:
- before: The operation after which the error occurred.
- reason: The reason for the error.
Returns:
- *error.Err: The new error. Never returns nil.
func NewErrAssertFail ¶
NewErrAssertFail creates a new error.Err error.
Parameters:
- msg: The message of the error.
Returns:
- *error.Err: The new error. Never returns nil.
func NewErrAt ¶
NewErrAt creates a new error.Err error.
Parameters:
- at: The operation at which the error occurred.
- reason: The reason for the error.
Returns:
- *error.Err: The new error. Never returns nil.
func NewErrBefore ¶
NewErrBefore creates a new error.Err error.
Parameters:
- after: The operation before which the error occurred.
- reason: The reason for the error.
Returns:
- *error.Err: The new error. Never returns nil.
func NewErrFix ¶
NewErrFix creates a new error.Err error.
Parameters:
- message: The message of the error.
- reason: The reason for the error.
Returns:
- *error.Err: The new error. Never returns nil.
func NewErrInvalidParameter ¶
NewErrInvalidParameter creates a new error.Err error.
Parameters:
- message: The message of the error.
Returns:
- *error.Err: The new error. Never returns nil.
func NewErrInvalidUsage ¶
NewErrInvalidUsage creates a new error.Err error.
Parameters:
- message: The message of the error.
- usage: The usage/suggestion to solve the problem.
Returns:
- *error.Err: The new error. Never returns nil.
func NewErrNilParameter ¶
NewErrNilParameter creates a new error.Err error.
Parameters:
- parameter: the name of the invalid parameter.
Returns:
- *error.Err: The new error. Never returns nil.
func NewErrNoSuchKey ¶
NewErrNoSuchKey creates a new error.Err error.
Parameters:
- key: The key that does not exist.
Returns:
- *error.Err: The new error. Never returns nil.
Types ¶
type ErrorCode ¶
type ErrorCode int
const ( // BadParameter occurs when a parameter is invalid or is not // valid for some reason. For example, a nil pointer when nil // pointers are not allowed. BadParameter ErrorCode = iota // InvalidUsage occurs when users call a function without // proper setups or preconditions. InvalidUsage // FailFix occurs when a struct cannot be fixed or resolved // due to an invalid internal state. FailFix // OperationFail occurs when an operation cannot be completed // due to an internal error. OperationFail // NoSuchKey occurs when a context key is requested but does // not exist. NoSuchKey // AssertFail occurs when an assertion fails. AssertFail )