Skip to content
tehsphinxPublic

About

Go errors additions

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

errs

The errs package is meant to be used in combination with the default errors package. It adds error types that can be used in combination e.g. to have a call stack in the error chain.

Usage

package main

import (
	"encoding/json"
	"errors"
	"fmt"

	"github.com/tehsphinx/cstack"
	"github.com/tehsphinx/errs"
)

func main() {
	err1 := createErr()
	err2 := wrapErr()

	stackStr := errs.MarshalStack(err1)
	stackSlice := errs.StackFrames(err2)

	jsonBts, _ := json.Marshal(stackSlice)
	fmt.Println(stackStr)
	fmt.Println(string(jsonBts))
}

func createErr() error {
	return errs.New("new error with stack")
}

func wrapErr() error {
	err := errors.New("wrapped with stack: error without stack")
	return errs.WithStack(err)
}

About

Go errors additions

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages