oof

package module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2023 License: MIT Imports: 5 Imported by: 1

README

oof

Errors with stack traces for golang

Go docs

Usage

import "github.com/hashibuto/oof"

Wrap an error and include a stack trace

err := method(xyz)
if err != nil {
    return oof.Trace(err)
}

Wrap an error and include a stack trace, with an annotation

err := method(xyz)
if err != nil {
    return oof.Tracef("This is my error: %w", err)
}

Example output

2022/09/18 05:27:17 Hello, this is my error: Special error occurred: SpecialError
goroutine 7 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x65
github.com/hashibuto/oof.Tracef({0x52e6b9, 0x1b}, {0xc00009fee8, 0x1, 0x1})
        /home/me/oof/oof.go:67 +0xb8
github.com/hashibuto/oof.ApplicationLevelCaller1()
        /home/me/oof/oof_test.go:36 +0x99
github.com/hashibuto/oof.TestTracef(0xc000007ba0)
        /home/me/oof/oof_test.go:57 +0x25
testing.tRunner(0xc000007ba0, 0x534b20)
        /usr/local/go/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:1493 +0x35f

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OofErrorInstance = &OofError{}

Functions

func Fatal added in v1.2.2

func Fatal(err error)

Fatal will log a fatal error message and cause the process to exit if and only if the provided err is non-nil. A full strack trace will be included.

func Fatalf added in v1.2.2

func Fatalf(fmtString string, args ...any)

Fatalf will log a fatal error message and cause the process to exit if and only if the provided err is non-nil. Additionally, a user specified message will be logged. A full strack trace will be included.

func GetTotalOofs added in v1.2.0

func GetTotalOofs() uint64

GetTotalOofs returns the total number of times oof.Trace has been called

func StripTrace added in v1.2.1

func StripTrace(err error) error

StripTrace strips the stack trace from an error

func Trace added in v1.0.0

func Trace(err error) error

Trace wraps the error in an OofError and captures the stack, along with the original error If the supplied error is nil, Trace will return nil

func Tracef added in v1.0.0

func Tracef(fmtString string, args ...any) error

Tracef wraps the error in an OofError and captures the stack, along with the original error and provides annotation If the supplied error is nil, Tracef will return nil

Types

type OofError

type OofError struct {
	OrigError error
	// contains filtered or unexported fields
}

func (*OofError) Error

func (e *OofError) Error() string

Error returns a string representation of the error

func (*OofError) Is

func (e *OofError) Is(target error) bool

func (*OofError) StripTrace added in v1.2.1

func (e *OofError) StripTrace()

StripTrace strips the stack trace from an error

func (*OofError) Unwrap added in v1.1.0

func (e *OofError) Unwrap() error

Unwrap will recursively unwrap the error, returning the original error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL