All Projects → emperror → Errors

emperror / Errors

Licence: other
Drop-in replacement for the standard library errors package and github.com/pkg/errors

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Errors

go-errors
Flexible, general-purpose error handling for Go.
Stars: ✭ 17 (-80.68%)
Mutual labels:  stacktrace, errors, error
Error Report
前端异常上报
Stars: ✭ 20 (-77.27%)
Mutual labels:  errors, error
Nginx Error Pages
Cute Error Pages for your nginx web server
Stars: ✭ 166 (+88.64%)
Mutual labels:  errors, error
Bugsnag Node
[DEPRECATED] Please upgrade to our Universal JS notifier "@bugsnag/js" • https://github.com/bugsnag/bugsnag-js
Stars: ✭ 48 (-45.45%)
Mutual labels:  errors, error
Node Common Errors
Common error classes and utility functions
Stars: ✭ 247 (+180.68%)
Mutual labels:  errors, error
failure
An error handling package for Go.
Stars: ✭ 24 (-72.73%)
Mutual labels:  errors, error
Bugsnag Go
Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
Stars: ✭ 155 (+76.14%)
Mutual labels:  errors, error
errors
errors with paired message and caller stack frame
Stars: ✭ 19 (-78.41%)
Mutual labels:  stacktrace, errors
Traceback with variables
Adds variables to python traceback. Simple, lightweight, controllable. Debug reasons of exceptions by logging or pretty printing colorful variable contexts for each frame in a stacktrace, showing every value. Dump locals environments after errors to console, files, and loggers. Works in Jupyter and IPython. Install with pip or conda.
Stars: ✭ 509 (+478.41%)
Mutual labels:  errors, stacktrace
Tracerr
Golang errors with stack trace and source fragments.
Stars: ✭ 646 (+634.09%)
Mutual labels:  errors, stacktrace
Make Error Cause
Make your own nested errors
Stars: ✭ 36 (-59.09%)
Mutual labels:  error
C V2x
Analytical Models of the Performance of C-V2X Mode 4 Vehicular Communications
Stars: ✭ 38 (-56.82%)
Mutual labels:  error
Go Errortree
Go library for handling errors organized as a tree
Stars: ✭ 59 (-32.95%)
Mutual labels:  error
Bugsnag Python
Official bugsnag error monitoring and error reporting for django, flask, tornado and other python apps.
Stars: ✭ 69 (-21.59%)
Mutual labels:  errors
Panic Overlay
Displays JS errors in browsers. Shows sources. Use with any framework. 💥✨
Stars: ✭ 50 (-43.18%)
Mutual labels:  stacktrace
Errorstacks
Tiny library to parse error stack traces
Stars: ✭ 29 (-67.05%)
Mutual labels:  error
Therror
Create and throw node errors like a boss
Stars: ✭ 11 (-87.5%)
Mutual labels:  errors
Seriouscode
This header file enforces Clang warnings to bu turned-on for specific flags (almost everyone, at least each one I was able to find).
Stars: ✭ 68 (-22.73%)
Mutual labels:  error
Oops
😥A library for android that help to show the layout of loading, error, empty etc.
Stars: ✭ 49 (-44.32%)
Mutual labels:  error
Thoth
An Error Logger for Go
Stars: ✭ 22 (-75%)
Mutual labels:  error

Emperror: Errors Mentioned in Awesome Go

GitHub Workflow Status Codecov Go Report Card Go Version PkgGoDev FOSSA Status

Drop-in replacement for the standard library errors package and github.com/pkg/errors.

This is a single, lightweight library merging the features of standard library errors package and github.com/pkg/errors. It also backports a few features (like Go 1.13 error handling related features).

Standard library features:

  • New creates an error with stack trace
  • Unwrap supports both Go 1.13 wrapper (interface { Unwrap() error }) and pkg/errors causer (interface { Cause() error }) interface
  • Backported Is and As functions

github.com/pkg/errors features:

  • New, Errorf, WithMessage, WithMessagef, WithStack, Wrap, Wrapf functions behave the same way as in the original library
  • Cause supports both Go 1.13 wrapper (interface { Unwrap() error }) and pkg/errors causer (interface { Cause() error }) interface

Additional features:

  • NewPlain creates a new error without any attached context, like stack trace
  • Sentinel is a shorthand type for creating constant error
  • WithStackDepth allows attaching stack trace with a custom caller depth
  • WithStackDepthIf, WithStackIf, WrapIf, WrapIff only annotate errors with a stack trace if there isn't one already in the error chain
  • Multi error aggregating multiple errors into a single value
  • NewWithDetails, WithDetails and Wrap*WithDetails functions to add key-value pairs to an error
  • Match errors using the match package

Installation

go get emperror.dev/errors

Usage

package main

import "emperror.dev/errors"

// ErrSomethingWentWrong is a sentinel error which can be useful within a single API layer.
const ErrSomethingWentWrong = errors.Sentinel("something went wrong")

// ErrMyError is an error that can be returned from a public API.
type ErrMyError struct {
	Msg string
}

func (e ErrMyError) Error() string {
	return e.Msg
}

func foo() error {
	// Attach stack trace to the sentinel error.
	return errors.WithStack(ErrSomethingWentWrong)
}

func bar() error {
	return errors.Wrap(ErrMyError{"something went wrong"}, "error")
}

func main() {
	if err := foo(); err != nil {
		if errors.Cause(err) == ErrSomethingWentWrong { // or errors.Is(ErrSomethingWentWrong)
			// handle error
		}
	}

	if err := bar(); err != nil {
		if errors.As(err, &ErrMyError{}) {
			// handle error
		}
	}
}

Match errors:

package main

import (
    "emperror.dev/errors"
    "emperror.dev/errors/match"
)

// ErrSomethingWentWrong is a sentinel error which can be useful within a single API layer.
const ErrSomethingWentWrong = errors.Sentinel("something went wrong")

type clientError interface{
    ClientError() bool
}

func foo() error {
	// Attach stack trace to the sentinel error.
	return errors.WithStack(ErrSomethingWentWrong)
}

func main() {
    var ce clientError
    matcher := match.Any{match.As(&ce), match.Is(ErrSomethingWentWrong)}

	if err := foo(); err != nil {
		if matcher.MatchError(err) {
			// you can use matchers to write complex conditions for handling (or not) an error
            // used in emperror
		}
	}
}

Development

Contributions are welcome! :)

  1. Clone the repository
  2. Make changes on a new branch
  3. Run the test suite:
    ./pleasew build
    ./pleasew test
    ./pleasew gotest
    ./pleasew lint
    
  4. Commit, push and open a PR

License

The MIT License (MIT). Please see License File for more information.

Certain parts of this library are inspired by (or entirely copied from) various third party libraries. Their licenses can be found in the Third Party License File.

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].