errors

package
v0.0.0-...-fee78ac Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// general error codes, range: 1000 ~ 1999
	ErrBadRequest      = NewErrorCode(1000, badRequest, "err.bad.request")
	ErrIllegalArgument = NewErrorCode(1001, illegalArgument, "err.illegal.argument")
	ErrUnexpected      = NewErrorCode(1002, unexpected, "err.unexpected")
	ErrKnown           = NewErrorCode(1010, known, "err.known")

	// ob operation error codes, range: 10000 ~ 10999
	ErrUserPermissionDenied = NewErrorCode(10000, unauthorized, "err.user.permission.denied")
	ErrUnauthorized         = NewErrorCode(10008, unauthorized, "err.unauthorized")
	ErrObclusterNotFound    = NewErrorCode(10009, known, "err.obcluster.not.found")

	// task error codes, range: 2300 ~ 2399
	ErrTaskNotFound     = NewErrorCode(2300, notFound, "err.task.not.found")
	ErrTaskCreateFailed = NewErrorCode(2301, known, "err.task.create.failed")
)

Functions

func Errorf

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

Errorf returns an error with the supplied formatted message.

func GetMessage

func GetMessage(lang language.Tag, errorCode ErrorCode, args []interface{}) string

GetMessage will get message from i18n bundle and format it with args

func IsTaskNotFoundErr

func IsTaskNotFoundErr(err error) bool

func IsUnkonwnTimeZoneErr

func IsUnkonwnTimeZoneErr(err error) bool

func New

func New(message string) error

New returns an error with the supplied message.

func Wrap

func Wrap(err error, message string) error

Wrap returns an error annotating err with a stack trace

func Wrapf

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

Wrapf returns an error annotating err with a stack trace

Types

type ErrorCode

type ErrorCode struct {
	Code int
	Kind ErrorKind
	// contains filtered or unexported fields
}

ErrorCode includes code, kind and key.

func NewErrorCode

func NewErrorCode(code int, kind ErrorKind, key string) ErrorCode

NewErrorCode will create a new ErrorCode and append it to errorCodes

type ErrorKind

type ErrorKind = int

type OcsAgentError

type OcsAgentError struct {
	ErrorCode ErrorCode     // error code
	Args      []interface{} // args for error message formatting
}

OcsAgentError defines ocsagent error and implements error interface.

func Occur

func Occur(errorCode ErrorCode, args ...interface{}) *OcsAgentError

Occur returns *OcsAgentError composed of errorcode and args

func Occurf

func Occurf(errorCode ErrorCode, format string, args ...interface{}) *OcsAgentError

Occurf formats according to a format specifier (The first one of the `args`) and returns the resulting string as a value that satisfies `OcsAgentError.Args`.

func (OcsAgentError) DefaultMessage

func (e OcsAgentError) DefaultMessage() string

DefaultMessage will return err default message.

func (OcsAgentError) Error

func (e OcsAgentError) Error() string

Error will return error string.

func (OcsAgentError) Message

func (e OcsAgentError) Message(lang language.Tag) string

Message will return error message composed of errorcode and args.

Jump to

Keyboard shortcuts

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