Skip to content

bikbah/stackerror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stackerror

PkgGoDev

Simple golang package to handle errors with stack info

Usage

  1. Install

    go get -v github.com/bikbah/stackerror
    
  2. Use in error returning code:

    package main
    
    import (
        "errors"
        "log"
    
        "github.com/bikbah/stackerror"
    )
    
    func main() {
        if err := f(); err != nil {
            // prints error with stack
            log.Fatal(err)
        }
    }
    
    func f() error {
        if err := g(); err != nil {
            return stackerror.New(err)
        }
    
        return nil
    }
    
    func g() error {
        return errors.New("error in stack depth")
    }
  3. Output

    2023/11/01 23:48:16 error in stack depth
    /dev/go/src/test/stackerror/main.go:18[main.f]
    /dev/go/src/test/stackerror/main.go:11[main.main]
    /usr/local/go/src/runtime/proc.go:267[runtime.main]
    /usr/local/go/src/runtime/asm_arm64.s:1197[runtime.goexit]
    exit status 1