Categorygithub.com/IguteChung/go-errors
modulepackage
0.0.0-20190819063352-2238e12fb826
Repository: https://github.com/igutechung/go-errors.git
Documentation: pkg.go.dev

# README

go-errors

A simple Go error utility to record the error stack trace, which supports customized formatting and is easy to migrate.

How to

Replace import paths of import "errors" by:

import "github.com/IguteChung/go-errors"

Replace all the occurences of fmt.Errorf by:

errors.Errorf("something wrong: %v", err)

You are done, let's get the stacktrace

fmt.Println(errors.StackTrace(err))

Output:

/tmp/sandbox647637562/prog.go:24
/tmp/sandbox647637562/prog.go:19
/tmp/sandbox647637562/prog.go:14

More customization

Apply custom format for stack trace:

func init() {
	errors.ApplyFormatter("foo\n\tfile.go:152\n")
}

Output:

main.bar
	/tmp/sandbox639852497/prog.go:24
main.foo
	/tmp/sandbox639852497/prog.go:19
main.main
	/tmp/sandbox639852497/prog.go:14

# Packages

No description provided by the author

# Functions

ApplyFormatter specifies the formatter for errorTracer.
Cause returns the original error of a traceable error.
Errorf creates a traceable error with formatted message.
GrpcError creates a traceable error with message and gRPC status code.
GrpcErrorf creates a traceable error with formatted message and gRPC status code.
New creates a traceable error with message.
StackTrace prints the stack trace with given error by the formatter.
Wrap wraps an error into a traceable error.
WrapMessage wraps an error into a traceable error with message.
WrapMessagef wraps an error into a traceable error with formatted message.

# Constants

constants for Stack formatters.
constants for Stack formatters.
constants for Stack formatters.
constants for Stack formatters.

# Type aliases

Formatter defines how stack trace is formatted.