gerror

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause returns the root cause gerror of <err>.

func Code

func Code(err error) int

Cause returns the gerror code of current gerror. It returns -1 if it has no gerror code or it does not implements interface Code.

func Current

func Current(err error) error

Current creates and returns the current level gerror. It returns nil if current level gerror is nil.

func New

func New(text string) error

New creates and returns an gerror which is formatted from given text.

func NewCode

func NewCode(code int, text string) error

NewCode creates and returns an gerror that has gerror code and given text.

Example
package main

import (
	"fmt"
	"gitee.com/KotlinToGo/pkg/gerror"
)

func main() {
	err := gerror.NewCode(10000, "My Error")
	fmt.Println(err.Error())
	fmt.Println(gerror.Code(err))

}
Output:

My Error
10000

func NewCodeSkip

func NewCodeSkip(code, skip int, text string) error

NewCodeSkip creates and returns an gerror which has gerror code and is formatted from given text. The parameter <skip> specifies the stack callers skipped amount.

func NewCodeSkipf

func NewCodeSkipf(code, skip int, format string, args ...interface{}) error

NewCodeSkipf returns an gerror that has gerror code and formats as the given format and args. The parameter <skip> specifies the stack callers skipped amount.

func NewCodef

func NewCodef(code int, format string, args ...interface{}) error

NewCodef returns an gerror that has gerror code and formats as the given format and args.

Example
package main

import (
	"fmt"
	"gitee.com/KotlinToGo/pkg/gerror"
)

func main() {
	err := gerror.NewCodef(10000, "It's %s", "My Error")
	fmt.Println(err.Error())
	fmt.Println(gerror.Code(err))

}
Output:

It's My Error
10000

func NewSkip

func NewSkip(skip int, text string) error

NewSkip creates and returns an gerror which is formatted from given text. The parameter <skip> specifies the stack callers skipped amount.

func NewSkipf

func NewSkipf(skip int, format string, args ...interface{}) error

NewSkipf returns an gerror that formats as the given format and args. The parameter <skip> specifies the stack callers skipped amount.

func Newf

func Newf(format string, args ...interface{}) error

Newf returns an gerror that formats as the given format and args.

func Next

func Next(err error) error

Next returns the next level gerror. It returns nil if current level gerror or the next level gerror is nil.

func Stack

func Stack(err error) string

Stack returns the stack callers as string. It returns the gerror string directly if the <err> does not support stacks.

func Wrap

func Wrap(err error, text string) error

Wrap wraps gerror with text. It returns nil if given err is nil.

func WrapCode

func WrapCode(code int, err error, text string) error

WrapCode wraps gerror with code and text. It returns nil if given err is nil.

Example
package main

import (
	"errors"
	"fmt"
	"gitee.com/KotlinToGo/pkg/gerror"
)

func main() {
	err1 := errors.New("permission denied")
	err2 := gerror.WrapCode(10000, err1, "Custom Error")
	fmt.Println(err2.Error())
	fmt.Println(gerror.Code(err2))

}
Output:

Custom Error: permission denied
10000

func WrapCodeSkip

func WrapCodeSkip(code, skip int, err error, text string) error

WrapCodeSkip wraps gerror with code and text. It returns nil if given err is nil. The parameter <skip> specifies the stack callers skipped amount.

func WrapCodeSkipf

func WrapCodeSkipf(code, skip int, err error, format string, args ...interface{}) error

WrapCodeSkipf wraps gerror with code and text that is formatted with given format and args. It returns nil if given err is nil. The parameter <skip> specifies the stack callers skipped amount.

func WrapCodef

func WrapCodef(code int, err error, format string, args ...interface{}) error

WrapCodef wraps gerror with code and format specifier. It returns nil if given <err> is nil.

Example
package main

import (
	"errors"
	"fmt"
	"gitee.com/KotlinToGo/pkg/gerror"
)

func main() {
	err1 := errors.New("permission denied")
	err2 := gerror.WrapCodef(10000, err1, "It's %s", "Custom Error")
	fmt.Println(err2.Error())
	fmt.Println(gerror.Code(err2))

}
Output:

It's Custom Error: permission denied
10000

func WrapSkip

func WrapSkip(skip int, err error, text string) error

WrapSkip wraps gerror with text. It returns nil if given err is nil. The parameter <skip> specifies the stack callers skipped amount.

func WrapSkipf

func WrapSkipf(skip int, err error, format string, args ...interface{}) error

WrapSkipf wraps gerror with text that is formatted with given format and args. It returns nil if given err is nil. The parameter <skip> specifies the stack callers skipped amount.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf returns an gerror annotating err with a stack trace at the point Wrapf is called, and the format specifier. It returns nil if given <err> is nil.

Types

type Error

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

Error is custom gerror for additional features.

func (*Error) Cause

func (err *Error) Cause() error

Cause returns the root cause gerror.

func (*Error) Code

func (err *Error) Code() int

Code returns the gerror code. It returns -1 if it has no gerror code.

func (*Error) Current

func (err *Error) Current() error

Current creates and returns the current level gerror. It returns nil if current level gerror is nil.

func (*Error) Error

func (err *Error) Error() string

Error implements the interface of Error, it returns all the gerror as string.

func (*Error) Format

func (err *Error) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%v, %s : Print all the gerror string; %-v, %-s : Print current level gerror string; %+s : Print full stack gerror list; %+v : Print the gerror string and full stack gerror list;

func (*Error) MarshalJSON

func (err *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal. Note that do not use pointer as its receiver here.

func (*Error) Next

func (err *Error) Next() error

Next returns the next level gerror. It returns nil if current level gerror or the next level gerror is nil.

func (*Error) Stack

func (err *Error) Stack() string

Stack returns the stack callers as string. It returns an empty string if the <err> does not support stacks.

Jump to

Keyboard shortcuts

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