Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nofeaturesonlybugs/errors

golang extended error package.
https://github.com/nofeaturesonlybugs/errors

error-handling error-reporting errors go golang stack stacktrace

Last synced: 8 days ago
JSON representation

golang extended error package.

Awesome Lists containing this project

README

        

[![Go Reference](https://pkg.go.dev/badge/github.com/nofeaturesonlybugs/errors.svg)](https://pkg.go.dev/github.com/nofeaturesonlybugs/errors)
[![Go Report Card](https://goreportcard.com/badge/github.com/nofeaturesonlybugs/errors)](https://goreportcard.com/report/github.com/nofeaturesonlybugs/errors)
[![Build Status](https://app.travis-ci.com/nofeaturesonlybugs/errors.svg?branch=master)](https://app.travis-ci.com/nofeaturesonlybugs/errors)
[![codecov](https://codecov.io/gh/nofeaturesonlybugs/errors/branch/master/graph/badge.svg)](https://codecov.io/gh/nofeaturesonlybugs/errors)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

golang package for enhanced errors that capture file and line number information, the call stack, relevant identifiers, and a handle back to the original error for type switching.

Replacement for fmt.Errorf(...):

```go
err := errors.Errorf("Failed to do something; here's a value %v",len(data))
fmt.Printf("%#v\n",err) // Prints full stack trace.
```

Wrap another function's error:

```go
_, err := net.Dial( "tcp", "localhost:8080" )
if err != nil {
return errors.Go( err )
}
```

Obtain the original error in order to type switch:

```go
func connect() error {
_, err := net.Dial( "tcp", "localhost:0" )
if err != nil {
return errors.Go( err )
}
return nil
}

err := connect()
switch errors.Original( err ).(type) {
case *net.OpError:
// We know the original type!
}
```

See the godoc link for more information.