Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureCallerInfo ¶
func CaptureCallerInfo(enable bool)
CaptureCallerInfo controls whether the caller info should be captured when a new error is generated.
This function enables or disables the capture of the caller information globally for this package. This call is thread-safe.
func StripCallerFilePrefixes ¶
func StripCallerFilePrefixes(prefixes ...string)
StripCallerFilePrefixes allows you to specify a list of file prefixes that should be stripped from the file path when capturing the caller information.
Only the first matching prefix will be stripped from the file path.
This function affects all CallerInfo objects generated globally by this package. This call is thread-safe.
Types ¶
type CallerInfo ¶
type CallerInfo struct {
// File is the name of the file in which the error occurred, relative to the package root.
File string `json:"file"`
// Line is the line number at which the error occurred.
Line int `json:"line"`
// Func is the name of the function in which the error occurred.
Func string `json:"func"`
}
CallerInfo holds information about the location from which the error was generated.
func DefaultCallerInfo ¶
func DefaultCallerInfo() *CallerInfo
DefaultCallerInfo returns a default CallerInfo that indicates that no caller information was captured.
func GetCallerInfo ¶
func GetCallerInfo(skip int) *CallerInfo
GetCallerInfo retrieves the file path, line number, and function name of the caller, formatting the file path to be relative to the package directory.
If the caller information is not available, a default CallerInfo is returned.
The 'skip' parameter indicates how many stack frames to ascend with 0 being the immediate caller of this function.
This function does not have to be called directly if you are using the New, Newf, Wrap or Wrapf functions to generate errors and you have enabled caller capture using CaptureCallerInfo.
type Error ¶
type Error interface {
error
json.Marshaler
// Attrs should return a map of attributes associated with the error.
Attrs() map[string]any
// Caller should return the information on where the error was generated.
Caller() CallerInfo
// Code should return the error code.
Code() int
// Is should return true if the wrapped error inside the object matches the given error, false otherwise.
Is(error) bool
// String should return a string representation of the error.
//
// Unlike the Error() method, this function may include additional information such as the caller details or
// attributes in any format (eg: plaintext or JSON).
String() string
// WithAttr should add an attribute to the error and return itself.
WithAttr(key string, value any) Error
// WithAttrs should add attributes to the error and return itself.
WithAttrs(attrs map[string]any) Error
}
Error is the interface implemented by extended errors.