Skip to content
This repository was archived by the owner on Jun 17, 2026. It is now read-only.

cosygreen/errs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warning

This repository has moved to GitLab: https://git.cosy.green/packages/errs

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/cosygreen/errs"
	"github.com/tehsphinx/cstack"
)

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

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages

  • Go 100.0%