Categorygithub.com/TheDSCPL/minimal-errors
modulepackage
1.0.1
Repository: https://github.com/thedscpl/minimal-errors.git
Documentation: pkg.go.dev

# README

Minimal Go errors

This package is a drop-in replacement for the standard library's errors package.

It then the functionalities from the github.com/pkg/errors package that are missing from the standard library. The difference from this package to github.com/pkg/errors is that this package does not automatically add a stack trace to the error, but the user can add one by calling errors.WithStack() and passing in another error.

Creating the stacktrace is a costly operation, so it is not done by default. This package is meant to be used in situations where the stacktrace is not needed, or where the stacktrace is added manually.

All the functions in this package that are the same as the standard library's errors package are actually just vars that are set to the same value as the standard library's errors package. This means that this package can be used as a drop-in replacement for the standard library's errors package and has minimal implementation and stable API.

Usage

package main

import "github.com/TheDSCPL/minimal-errors"

func main() {
    err := errors.New("this is an error")
    err = errors.WithStack(err)
}

# Functions

Metadata returns the metadata associated with an error.
Redefine returns a new error that wraps baseErr but keeps the message of oldErr.
StackTrace returns the underlying cause of the error, if possible.
TypedDeepMetadata returns the metadata of the specified type associated with an error or any of its wrappers.
TypedMetadata returns the metadata associated with an error.
WithCause returns an error that annotates err with the provided cause.
WithMetadata annotates an error with metadata.
Wrap returns a new error that wraps the error passed in the err parameter.

# Variables

As finds the first error in err's chain that matches target, and if one is found, sets target to that error value and returns true.
Cause returns the underlying cause of the error, if possible.
Errorf formats according to a format specifier and returns the string as a value that satisfies error.
Is reports whether any error in err's chain matches target.
New returns an error that formats as the given text.
Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error.
WithStack annotates err with a stack trace at the point WithStack was called.

# Type aliases

No description provided by the author
No description provided by the author