stackerror

package module
v0.0.0-...-976d888 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: Apache-2.0 Imports: 7 Imported by: 10

README

Overview

Build Status codecov Go Report Card

Go native error library is a great design, but in some scenarios, there are some flaws. In a complex business scenario, it is necessary to quickly locate the code exception location, but the native error only supports viewing the stack data when panic is used. When multiple returns or panic / recover are used, it is difficult to get the actual starting point of the exception. This makes code debugging a lot of difficulties!

Get code

method 1

  go get github.com/lingdor/stackerror

##method 2

go.mod

  require github.com/lingdor/stackerror v0.1.5
  go mod download

#Usage

Get a stackError

err:=stackerror.New("your message")
return err

Throw a stackerror

stackerror.Panic("your message")

Grace method checking error

func aa() error {
    return stackerror.New("err")
}

func main(){
	defer func(){
		if err:=recover();err!=nil {
			fmt.Println(err)
		}
	}()

	err:=aa()
	stackerror.CheckPanic(err)
}

Output:
*stackerror.stackError : err
at main.aa( /Users/user/go/testApp/src/main/aa.go:8 )
at main.main( /Users/user/go/testApp/src/main/aa.go:18 )
at runtime.main( /usr/local/Cellar/go/1.13.4/libexec/src/runtime/proc.go:203 )\

Thanks

Documentation

Overview

Package stackerror is a have stack information with error library

see README.md for more info.

Index

Constants

This section is empty.

Variables

View Source
var MaxStackSize = 1024

MaxStackSize Max byte size of formating stack information

View Source
var StackMaxDeep = 16

StackMaxDeep Max deep with stack information

Functions

func CheckExitError

func CheckExitError(err error)

CheckExitError Check error and print after exit

func CheckPanic

func CheckPanic(err error)

CheckPanic check error and panic

func Panic

func Panic(errMsg string)

Panic make a stackError panic()

func PanicError

func PanicError(err error)

PanicError make a stacError panic() with error

Types

type StackError

type StackError interface {
	error
	GetMsg() string
	GetStacks() []runtime.Frame
	GetChild() error
}

StackError stackError package information interface

func New

func New(msg string) StackError

New Get a StackError object with msg

func NewParent

func NewParent(msg string, child error) StackError

NewParent Get a parent stackError object with msg and child

Jump to

Keyboard shortcuts

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