errorx

package
v0.0.0-...-ebe581b Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 28

Documentation

Index

Constants

View Source
const (
	ErrCodeInternal = "10001" // internal error
	ErrCodeParam    = "10002" // parameter error
	ErrCodeConfig   = "10003" // configuration error
	ErrCodeNotFound = "10004" // target not found
	ErrCodeEncoding = "10005" // encoding error

	ErrCodeNotAuthorized = "10006" // not authorized
	ErrCodeAlreadyExists = "10007" // duplicate item
	ErrCodeBadSignature  = "10008" // signature verification failed
	ErrCodeCrypto        = "10009" // cryptography computation error
	ErrCodeExpired       = "10010" // target expired

	ErrCodeReadBlockchain  = "10011" // errors occurred when reading data from blockchain
	ErrCodeWriteBlockchain = "10012" // errors occurred when writing data to blockchain
	ErrCodeAlreadyUpdate   = "10013" // duplicate updating error
)

error code list

View Source
const SuccessCode = "0"

define success code

Variables

View Source
var ErrNotFound = &Error{
	Code:    ErrCodeNotFound,
	Message: "not found",
}

Functions

func Example

func Example()

Example noop

func Internal

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

func Is

func Is(err error, code string) bool

Is compare if two codes are same

func New

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

New Create an error from code and message

func NewCode

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

NewCode Create an error by wrapping a existed error from outer package

will drop original code

func Parse

func Parse(err error) (code, message string)

Parse retrieve code and message 1. try to retrieve errorx.Error from err chain 2. try to unmarshal err.Error() into errorx.Error 3. or else an internal error with original err.Error()

func ParseAndWrap

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

ParseAndWrap decode and wrap errors from outer components

func TryParseFromString

func TryParseFromString(s string) (code, message string, success bool)

func Wrap

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

Wrap wrap error with a message

Types

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Error error of tc-worker

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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