Categorygithub.com/wirekang/first-error
modulepackage
0.0.0-20220327154840-df5385b66e83
Repository: https://github.com/wirekang/first-error.git
Documentation: pkg.go.dev

# README

first-error

Get stack trace where the error first wrapped with github.com/pkg/errors .WithStack()

Usage

Warp every error with WithStack.

if err != nil {
  err = errors.WithStack(err)
}

You can get stack trace of first wrapped error.


ferr.StackTrace(nil) // ""
ferr.StackTrace(err) // error1234 \n\n StackTrace: \n...

Example

error reporting with ferr.RecoverCallback()

https://github.com/wirekang/mouseable/blob/d3c97367718aef3f17de4a38412d8dc7e9a88f4c/internal/logic/logic.go#L80

defer ferr.RecoverCallback(
		func(msg string) {
			// Do something with msg.
		},
	)

# Functions

RecoverAndPrintAndExit prints stack trace and exit with exitCode if recover() returns non-nil value.
StackTrace is alias for StackTraceRange(err,0,100).
StackTraceRange returns stack trace with start/max frame range.