All Projects → ztrue → Tracerr

ztrue / Tracerr

Licence: mit
Golang errors with stack trace and source fragments.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Tracerr

Bugsnag Php
Bugsnag error monitoring and crash reporting tool for PHP apps
Stars: ✭ 475 (-26.47%)
Mutual labels:  error-handling, errors, debug
bugsnag-java
Bugsnag error reporting for Java.
Stars: ✭ 51 (-92.11%)
Mutual labels:  errors, error-handling, debug
errors
errors with paired message and caller stack frame
Stars: ✭ 19 (-97.06%)
Mutual labels:  stacktrace, errors, error-handling
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 (-21.21%)
Mutual labels:  error-handling, errors, stacktrace
go-errors
Flexible, general-purpose error handling for Go.
Stars: ✭ 17 (-97.37%)
Mutual labels:  stacktrace, errors, error-handling
Bugsnag React Native
Error monitoring and reporting tool for native exceptions and JS errors in React Native apps
Stars: ✭ 374 (-42.11%)
Mutual labels:  error-handling, debug, stacktrace
Bugsnag Ruby
Bugsnag error monitoring & reporting software for rails, sinatra, rack and ruby
Stars: ✭ 211 (-67.34%)
Mutual labels:  error-handling, errors, debug
Bugsnag Laravel
Bugsnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
Stars: ✭ 746 (+15.48%)
Mutual labels:  error-handling, errors, debug
Bugsnag Node
[DEPRECATED] Please upgrade to our Universal JS notifier "@bugsnag/js" • https://github.com/bugsnag/bugsnag-js
Stars: ✭ 48 (-92.57%)
Mutual labels:  error-handling, errors, debug
Panic Overlay
Displays JS errors in browsers. Shows sources. Use with any framework. 💥✨
Stars: ✭ 50 (-92.26%)
Mutual labels:  error-handling, debug, stacktrace
Bugsnag Go
Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
Stars: ✭ 155 (-76.01%)
Mutual labels:  error-handling, errors, debug
fail
Better error handling solution specially designed for web application servers
Stars: ✭ 27 (-95.82%)
Mutual labels:  errors, error-handling
Rollbar.js
Error tracking and logging from JS to Rollbar
Stars: ✭ 479 (-25.85%)
Mutual labels:  error-handling, errors
Whoops
PHP errors for cool kids
Stars: ✭ 12,646 (+1857.59%)
Mutual labels:  error-handling, errors
bugsnag-vue
[DEPRECATED] This package now lives within the monorepo for our Universal JS notifier "@bugsnag/js" • https://github.com/bugsnag/bugsnag-js
Stars: ✭ 26 (-95.98%)
Mutual labels:  error-handling, debug
rakered
The open source components from rake.red
Stars: ✭ 28 (-95.67%)
Mutual labels:  errors, error-handling
safe
🛡 PHP functions smarten up to throw exceptions instead of returning false or triggering errors.
Stars: ✭ 15 (-97.68%)
Mutual labels:  errors, error-handling
Bugsnag Cocoa
Bugsnag crash reporting for iOS, macOS and tvOS apps
Stars: ✭ 167 (-74.15%)
Mutual labels:  error-handling, errors
jsonerror
Makes Go error-handling a breeze!
Stars: ✭ 28 (-95.67%)
Mutual labels:  errors, error-handling
Reattempt
🤞 Give your functions another chance
Stars: ✭ 570 (-11.76%)
Mutual labels:  error-handling, errors

Golang Errors with Stack Trace and Source Fragments

GoDoc Report Coverage Status Build Status

Tired of uninformative error output? Probably this will be more convenient:

Output

Example

package main

import (
	"io/ioutil"

	"github.com/ztrue/tracerr"
)

func main() {
	if err := read(); err != nil {
		tracerr.PrintSourceColor(err)
	}
}

func read() error {
	return readNonExistent()
}

func readNonExistent() error {
	_, err := ioutil.ReadFile("/tmp/non_existent_file")
	// Add stack trace to existing error, no matter if it's nil.
	return tracerr.Wrap(err)
}

Find more executable examples in examples dir.

How to Use

Import

import "github.com/ztrue/tracerr"

Create New Error

err := tracerr.New("some error")

Or:

err := tracerr.Errorf("some error %d", num)

Add Stack Trace to Existing Error

If err is nil then it still be nil with no stack trace added.

err = tracerr.Wrap(err)

Print Error and Stack Trace

Stack trace will be printed only if err is of type tracerr.Error, otherwise just error text will be shown.

This will print error message and stack trace if any:

tracerr.Print(err)

This will add source code:

tracerr.PrintSource(err)

It's able to set up number of lines of code to display for each frame, which is 6 by default:

tracerr.PrintSource(err, 9)

Or to set up number of lines before and after traced line:

tracerr.PrintSource(err, 5, 2)

The same, but with color, which is much more useful:

tracerr.PrintSourceColor(err)
tracerr.PrintSourceColor(err, 9)
tracerr.PrintSourceColor(err, 5, 2)

Save Output to Variable

It's also able to save output to variable instead of printing it, which works the same way:

text := tracerr.Sprint(err)
text := tracerr.SprintSource(err)
text := tracerr.SprintSource(err, 9)
text := tracerr.SprintSource(err, 5, 2)

Get Stack Trace

Stack trace will be empty if err is not an instance of tracerr.Error.

frames := tracerr.StackTrace(err)

Or if err is of type tracerr.Error:

frames := err.StackTrace()

Get Original Error

Unwrapped error will be nil if err is nil and will be the same error if err is not an instance of tracerr.Error.

err = tracerr.Unwrap(err)

Or if err is of type tracerr.Error:

err = err.Unwrap()

Performance

Stack trace causes a performance overhead, depending on a stack trace depth. This can be insignificant in a number of situations (such as HTTP request handling), however, avoid of adding a stack trace for really hot spots where a high number of errors created frequently, this can be inefficient.

Benchmarks done on a MacBook Pro 2015 with go 1.11.

Benchmarks for creating a new error with a stack trace of different depth:

BenchmarkNew/5    200000    5646 ns/op    976 B/op   4 allocs/op
BenchmarkNew/10   200000   11565 ns/op    976 B/op   4 allocs/op
BenchmarkNew/20    50000   25629 ns/op    976 B/op   4 allocs/op
BenchmarkNew/40    20000   65833 ns/op   2768 B/op   5 allocs/op
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].