Skip to content

smquartz/errors

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smquartz/errors

Build Status Godoc Reference Coverage Status Go Report Card codebeat badge

Package errors adds stacktrace to errors in go.

This is particularly useful when you want to understand the state of execution when an error was returned unexpectedly.

It provides the type *Err which implements the standard golang error interface, so you can use this library interchangeably with code that is expecting a normal error return.

Usage

Full documentation is available on godoc, but here's a simple example:

package crashy

import "github.com/smquartz/errors"

var Crashed = errors.Errorf("oh dear")

func Crash() error {
    return errors.New(Crashed)
}

This can be called as follows:

package main

import (
    "crashy"
    "fmt"
    "github.com/smquartz/errors"
)

func main() {
    err := crashy.Crash()
    if err != nil {
        if errors.Is(err, crashy.Crashed) {
            fmt.Println(err.(*errors.Error).ErrorStack())
        } else {
            panic(err)
        }
    }
}

Meta-fu

This package is a fork of github.com/go-errors/errors that modifies its behaviour and adds compliance with github.com/pkg/errors.

This package is licensed under the MIT license, see LICENSE.MIT for details.