Skip to content
/ errs Public

A simple wrapper over the standard errors package to get error stack traces.

Notifications You must be signed in to change notification settings

f1monkey/errs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Errs

A simple wrapper over the standard errors package to get error stack traces.

Install

$ go get -v github.com/f1monkey/errs

Usage

package main

import (
    "errors"

    "github.com/f1monkey/errs"
)


func doSomething() error {
    // ...

    result, err := service.Do(ctx)
    if err != nil {
        return errs.Errorf("service err: %w", err) // stacktrace will be captured here
    }

    // ...
}

type stacktracer interface {
	StackTrace() []byte
}

func DoSomething() error {
    // ...

    if err := doSomething(); err != nil {
		var stacktraceErr *errs.Error
		// get stack trace, option 1: use errors.As()
		if errors.As(err, &stacktraceErr) {
			fmt.Println(stacktraceErr.StackTrace())
		}

		// get stack trace, option 2: use type assertion
		if e, ok := err.(stacktracer); ok {
			fmt.Println(e.StackTrace())
		}
	}

	// ...
}

About

A simple wrapper over the standard errors package to get error stack traces.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages