erro

package module
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 4 Imported by: 0

README

Erro: Faster and easier debugging in case of an error

Build state Go Version Version Issues Report

gopherbadger-tag-do-not-edit

Forked from snwfdhmp/errlog

Erro (pronounced 'arrow') is a simple libary that helps finding the reasons for errors in your Golang code. When an error is created through erro, the source of the failing code is shown together with the stack trace and the variables that led to the error.

Erro example outpuit

Introduction

Use Erro to help understanding errors and speed up debugging while you create amazing code :

  • Highlight source code
  • Detect and point out which func call is causing the fail
  • Pretty stack trace
  • No-op mode for production

Get started

Install
go get github.com/StephanSchmidt/erro

License information

MIT License

Contributors

Major
  • Stephan Schmidt: Author and maintainer
  • Martin Joly wrote the original errlog which this code is based on

Documentation

Overview

Package erro provides a simple object to enhance Go source code debugging

Example result:

$ go run myfailingapp.go
Program starting
error in main.main: something failed here
line 13 of /Users/StephanSchmidt/go/src/github.com/StephanSchmidt/sandbox/testerr.go
9: func main() {
10:     fmt.Println("Program starting")
11:     err := errors.Errorf("something failed here")
12:
13:     erro.Debug(err)
14:
15:     fmt.Println("End of the program")
16: }
exit status 1

You can configure your own logger with these options :

type Config struct {
	LinesBefore        int
	LinesAfter         int
	PrintStack         bool
	getData        bool
	PrintError         bool
	ExitOnDebugSuccess bool
}

Example :

debug := erro.NewLogger(&erro.Config{
	LinesBefore:        2,
	LinesAfter:         1,
	PrintError:         true,
	getData:        true,
	PrintStack:         false,
	ExitOnDebugSuccess: true,
})

// ...
if err != nil {
	debug.Debug(err)
	return
}

Outputs :

Error in main.someBigFunction(): I'm failing for no reason
line 41 of /Users/StephanSchmidt/go/src/github.com/StephanSchmidt/sandbox/testerr.go:41
33: func someBigFunction() {
...
40:     if err := someNastyFunction(); err != nil {
41:             debug.Debug(err)
42:             return
43:     }
exit status 1

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf added in v0.2.0

func Errorf(format string, source error, a ...any) error

func New

func New(errorString string, source error, a ...interface{}) error

func NewE added in v0.2.0

func NewE(myError error, source error, a ...interface{}) error

func SetDevModeOff added in v0.6.1

func SetDevModeOff()

func SetDevModeOn added in v0.6.1

func SetDevModeOn()

func SetLogger added in v0.6.1

func SetLogger(logger *zerolog.Logger)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL