error.go
error.go - Overview
This file provides error handling functions, including checking for errors, asserting conditions, wrapping errors with context, and combining errors.
Detailed Documentation
Check
- Purpose: Logs a fatal error if the provided error is not nil.
- Parameters:
err
(error): The error to check.
- Returns: None.
Check2
- Purpose: A convenience wrapper around
Check
, using the second argument as the error. - Parameters:
_
(interface<>): An ignored interface.err
(error): The error to check.
- Returns: None.
AssertTrue
- Purpose: Logs a fatal error if the provided boolean is false.
- Parameters:
b
(bool): The boolean to assert.
- Returns: None.
AssertTruef
- Purpose: Logs a fatal error with additional formatting if the provided boolean is false.
- Parameters:
b
(bool): The boolean to assert.format
(string): The format string for the error message.args
(...interface<>): The arguments to the format string.
- Returns: None.
Wrap
- Purpose: Wraps an error with an additional message, providing context.
- Parameters:
err
(error): The error to wrap.msg
(string): The message to add to the error.
- Returns: error: The wrapped error, or nil if the input error is nil and debugMode is false.
Wrapf
- Purpose: Wraps an error with a formatted message, providing context.
- Parameters:
err
(error): The error to wrap.format
(string): The format string for the message.args
(...interface<>): The arguments to the format string.
- Returns: error: The wrapped error.
CombineErrors
- Purpose: Combines two errors into a single error.
- Parameters:
one
(error): The first error.other
(error): The second error.
- Returns: error: A new error combining both, or nil if both are nil.
Code Examples
Not applicable.