GithubHelp home page GithubHelp logo

werr's Introduction

Disclaimer: private use and with my coworkers. It will break! feel free to copy-paste.

werr: opt-in traces in errors.

Add the name of the function/method and the file:line opt-in on each error to print a minimalist traceback with decorations.

Example:

> gotodo/vue.Issue() issue.go:29
read issue:
> gotodo/model.(*Project).GetIssueStr() issue.go:99
Erreur en lecture issue x: strconv.Atoi: parsing "x": invalid syntax

Usage

go get go.flibuste.net/werr

Wrap or create the error with one of the werr functions, it'll add the function/method name and the file:line in the string. Nothing more.

Wrap and Wrapf will wrap the error, like %w. Errorf is like fmt.Errorf with trace New is like errors.New with trace

Just print the error.

How to adapt a legacy app

Replace fmt.Errorf with werr.Errorf

sed -i 's/fmt.Errorf/werr.Errorf/g' *go

Replace errors.New with werr.New

sed -i 's/errors.New/werr.New/g' *go

Add trace + wrap to return err without decoration, like %w

sed -i 's/return err/return werr.Wrap(err)/g' *go

Add import go.flibuste.net/werr

goimports -w *.go

Find return err still not decorated ack 'return.*err$'

Be carefull when comparing err == ... to replace by errors.Is

werr's People

Contributors

flibustenet avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.