errors

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2019 License: MIT Imports: 12 Imported by: 14

README

errors

error handle for go

package errors_test

import (
	es "errors"
	"github.com/pubgo/errors"
	"testing"
)

func TestT(t *testing.T) {
	defer errors.Debug()

	errors.T(true, "test t")
}

func TestTT(t *testing.T) {
	defer errors.Debug()

	errors.TT(true, func(m *errors.M) {
		m.Msg("test tt").
			Tag("tag").
			M("k", "v")

	})
}

func TestWrap(t *testing.T) {
	defer errors.Debug()

	errors.Wrap(es.New("test"), "test")
}

func TestWrapM(t *testing.T) {
	defer errors.Debug()

	errors.WrapM(es.New("dd"), func(m *errors.M) {
		m.Msg("test")
	})
}

func testFunc() {
	defer errors.Handle(func() {})

	errors.WrapM(es.New("sbhbhbh"), func(m *errors.M) {
		m.Msg("test shhh").
			M("ss", 1).
			M("input", 2)
	})
}

func TestPanic(t *testing.T) {
	defer errors.Debug()

	testFunc()
	t.Log("ok")
}

func init11() {
	defer errors.Handle(func() {})

	//T(true, "sss")
	errors.TT(true, func(m *errors.M) {
		m.Msg("test tt")
	})
}

func TestT2(t *testing.T) {
	defer errors.Debug()

	init11()
}

func TestTry(t *testing.T) {
	defer errors.Debug()

	errors.Panic(errors.Try(errors.T, true, "sss"))
}

func TestTask(t *testing.T) {
	defer errors.Debug()

	errors.Wrap(errors.Try(func() {
		errors.Wrap(es.New("dd"), "err ")
	}), "test wrap")
}

func TestHandle(t *testing.T) {
	defer errors.Debug()

	func() {
		defer errors.Handle(func() {})

		errors.Wrap(es.New("hello error"), "sss")
	}()

}

func TestErrHandle(t *testing.T) {
	defer errors.Debug()

	errors.ErrHandle(errors.Try(errors.T, true, "test 12345"), func(err *errors.Err) {
		err.P()
	})

	errors.ErrHandle(errors.Try(errors.T, true, "test 12345"))

	errors.ErrHandle("ttt")
	errors.ErrHandle(es.New("eee"))
	errors.ErrHandle([]string{"dd"})
}

func TestIsZero(t *testing.T) {
	defer errors.Debug()

	var ss = func() map[string]interface{} {
		return make(map[string]interface{})
	}

	var ss1 = func() map[string]interface{} {
		return nil
	}

	var s = 1
	var ss2 map[string]interface{}
	t.Log(errors.IsZero(1))
	t.Log(errors.IsZero(1.2))
	t.Log(errors.IsZero(nil))
	t.Log(errors.IsZero("ss"))
	t.Log(errors.IsZero(map[string]interface{}{}))
	t.Log(errors.IsZero(ss()))
	t.Log(errors.IsZero(ss1()))
	t.Log(errors.IsZero(&s))
	t.Log(errors.IsZero(ss2))
}

func TestResp(t *testing.T) {
	defer errors.Resp(func(err *errors.Err) {
		err.StackTrace()
	})

	errors.T(true, "data handle")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cfg = struct {
	Debug bool
}{
	Debug: true,
}
View Source
var ErrTag = struct {
	UnknownErr string
}{
	UnknownErr: "unknown",
}

Functions

func Debug

func Debug()

func ErrHandle

func ErrHandle(err interface{}, fn ...func(err *Err))

func FnCost

func FnCost(f func()) time.Duration

func FnOf

func FnOf(fn interface{}, args ...interface{}) func() []reflect.Value

func Handle

func Handle(fn func())

func If

func If(b bool, t, f interface{}) interface{}

func IsZero added in v0.1.0

func IsZero(v interface{}) bool

func P

func P(d ...interface{})

func Panic

func Panic(err interface{})

func Resp

func Resp(fn func(err *Err))

func T

func T(b bool, msg string, args ...interface{})

func TT

func TT(b bool, fn func(m *M))

func Try

func Try(fn interface{}, args ...interface{}) func(...interface{}) (err error)

func Wrap

func Wrap(err interface{}, msg string, args ...interface{})

func WrapM

func WrapM(err interface{}, fn func(m *M))

Types

type Err

type Err struct {
	// contains filtered or unexported fields
}

func (*Err) Err

func (t *Err) Err() error

func (*Err) Error

func (t *Err) Error() string

func (*Err) P

func (t *Err) P()

func (*Err) StackTrace

func (t *Err) StackTrace() *_Err

func (*Err) Tag

func (t *Err) Tag() string

type ErrT added in v0.1.1

type ErrT func() (err error)

type FnT added in v0.1.0

type FnT func(cfn ...interface{}) (err error)

type M

type M struct {
	// contains filtered or unexported fields
}

func (*M) Caller

func (t *M) Caller(depth int) *M

func (*M) Load added in v0.0.5

func (t *M) Load() *M

func (*M) M

func (t *M) M(k string, v interface{}) *M

func (*M) Msg

func (t *M) Msg(format string, args ...interface{}) *M

func (*M) Tag

func (t *M) Tag(tag string) *M

Jump to

Keyboard shortcuts

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