errors

package
v0.0.0-...-1334a7b Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UNKNOWN.
	ErrUnknown = New("unknown").WithGRPCCode(ErrorCodeUnknown)

	// RESOURCE_NOT_FOUND.
	ErrResourceNotFound       = New("resource not found").WithGRPCCode(ErrorCodeResourceNotFound)
	ErrEventlogNotFound       = New("eventlog not found").WithGRPCCode(ErrorCodeEventlogNotFound)
	ErrSegmentNotFound        = New("segment not found").WithGRPCCode(ErrorCodeSegmentNotFound)
	ErrBlockNotFound          = New("block not found").WithGRPCCode(ErrorCodeBlockNotFound)
	ErrVolumeInstanceNotFound = New("volume instance not found").WithGRPCCode(ErrorCodeVolumeNotFound)

	// SERVICE_NOT_RUNNING.
	ErrServerNotStart            = New("server not start").WithGRPCCode(ErrorCodeServiceNotRunning)
	ErrSegmentServerHasBeenAdded = New("the segment server has been added").WithGRPCCode(
		ErrorCodeSegmentServerHasBeenAdded)
	ErrServiceState   = New("service state error").WithGRPCCode(ErrorCodeServiceStateError)
	ErrWorkerNotStart = New("worker not start").WithGRPCCode(ErrorCodeWorkerNotRunning)

	// SEGMENT_FULL.
	ErrSegmentFull           = New("segment full").WithGRPCCode(ErrorCodeSegmentFull)
	ErrSegmentNotEnoughSpace = New("not enough space").WithGRPCCode(ErrorCodeSegmentNoEnoughSpace)
	ErrOffsetUnderflow       = New("the offset underflow").WithGRPCCode(ErrorCodeOffsetUnderflow)
	ErrOffsetOverflow        = New("the offset overflow").WithGRPCCode(ErrorCodeOffsetOverflow)
	ErrOffsetOnEnd           = New("the offset on end").WithGRPCCode(ErrorCodeOffsetOnEnd)
	ErrBlockNotSupported     = New("block not supported").WithGRPCCode(ErrorCodeBlockNotSupported)
	ErrNotWritable           = New("not writable").WithGRPCCode(ErrorCodeNotWritable)
	ErrNotReadable           = New("not readable").WithGRPCCode(ErrorCodeNotReadable)
	ErrTryAgain              = New("try again").WithGRPCCode(ErrorCodeTryAgain)
	ErrNoEndpoint            = New("no endpoint").WithGRPCCode(ErrorCodeNoEndpoint)
	ErrClosed                = New("closed").WithGRPCCode(ErrorCodeClosed)

	// INTERNAL.
	ErrInternal               = New("internal error").WithGRPCCode(ErrorCodeInternal)
	ErrTriggerWorker          = New("trigger worker error").WithGRPCCode(ErrorCodeTriggerWorker)
	ErrInvalidSegment         = New("invalid segment").WithGRPCCode(ErrorCodeInvalidSegment)
	ErrInvalidHeartBeat       = New("invalid heartbeat").WithGRPCCode(ErrorCodeInvalidHeartbeat)
	ErrVolumeInstanceNoServer = New("no segment server was bound to volume instance").WithGRPCCode(ErrorCodeVolumeNoServer)
	ErrJSONMarshal            = New("json marshal").WithGRPCCode(ErrorCodeJSONMarshal)
	ErrJSONUnMarshal          = New("json unmarshal").WithGRPCCode(ErrorCodeJSONUnmarshal)
	ErrAESEncrypt             = New("aes encrypt").WithGRPCCode(ErrorCodeAESEncrypt)
	ErrAESDecrypt             = New("aes decrypt").WithGRPCCode(ErrorCodeAESDecrypt)
	ErrUnmarshal              = New("unmarshal data failed").WithGRPCCode(ErrorCodeUnmarshal)
	ErrLambdaInvoke           = New("lambda invoke error").WithGRPCCode(ErrorCodeLambdaInvoke)
	ErrLambdaInvokeResponse   = New("lambda invoke response fail").WithGRPCCode(ErrorCodeLambdaInvokeResponse)
	ErrInvalidJSONPath        = New("invalid JSON path").WithGRPCCode(ErrorCodeInvalidJSONPath)
	ErrJSONPathNotExist       = New("JSON path not exist").WithGRPCCode(ErrorCodeJSONPathNotExist)

	// INVALID_REQUEST.
	ErrInvalidRequest          = New("invalid request").WithGRPCCode(ErrorCodeInvalidRequest)
	ErrInvalidArgument         = New("invalid argument").WithGRPCCode(ErrorCodeInvalidArgument)
	ErrCeSQLExpression         = New("ce sql expression invalid").WithGRPCCode(ErrorCodeCESQLExpression)
	ErrCelExpression           = New("cel expression invalid").WithGRPCCode(ErrorCodeCELExpression)
	ErrFilterAttributeIsEmpty  = New("filter dialect attribute is empty").WithGRPCCode(ErrorCodeFilterAttributeIsEmpty)
	ErrFilterMultiple          = New("filter multiple dialects found").WithGRPCCode(ErrorCodeFilterMultiple)
	ErrInvalidHeartBeatRequest = New("invalid heartbeat request").WithGRPCCode(ErrorCodeInvalidHeartbeatRequest)
	ErrVanusJSONParse          = New("invalid json").WithGRPCCode(ErrorCodeJSONParse)
	ErrTransformInputParse     = New("transform input invalid").WithGRPCCode(ErrorCodeTransformInputParse)
	ErrCorruptedEvent          = New("corrupted event").WithGRPCCode(ErrorCodeCorruptedEvent)

	// ErrResourceAlreadyExist.
	ErrResourceAlreadyExist = New("resource already exist").WithGRPCCode(ErrorCodeResourceExist)

	// ErrNotLeader not leader.
	ErrNotLeader          = New("not leader").WithGRPCCode(ErrorCodeNotLeader)
	ErrNotReady           = New("not ready").WithGRPCCode(ErrorCodeNotReady)
	ErrNoControllerLeader = New("no leader controller found").WithGRPCCode(ErrorCodeNoControllerLeader)
	ErrNotRaftLeader      = New("the node is not raft leader").WithGRPCCode(ErrorCodeNotRaftLeader)

	// RESOURCE_EXHAUSTED.
	ErrNoAvailableEventlog = New("no eventlog available").WithGRPCCode(ErrorCodeResourceExhausted)

	// RESOURCE_CAN_NOT_OP.
	ErrResourceCanNotOp = New("resource can not operation").WithGRPCCode(ErrorCodeResourceCanNotOp)

	ErrUnauthenticated  = New("unauthenticated").WithGRPCCode(ErrorCodeUnauthenticated)
	ErrPermissionDenied = New("permissionDenied").WithGRPCCode(ErrorCodePermissionDenied)
)

Functions

func Chain

func Chain(errs ...error) error

Chain method can group many errors as a single error. this is a helpful method if there are many errors will be occurred in one method.

Example: if we have a loop in one method, and each iterator create a goroutine, each goroutine may an error occurred, but we have to wait all goroutine done, in this situation, we can use this method to collect all errors occurred in different goroutine.

Notice: this method is not CONCURRENCY SAFETY. you can see somewhere call this function to know more details about how to use this method.

func ConvertToGRPCError

func ConvertToGRPCError(err error) error

ConvertToGRPCError convert an internal error to an exported error defined in gRPC.

func Is

func Is(err error, target error) bool

func UnwrapOrUnknown

func UnwrapOrUnknown(err error) error

Types

type ErrorCode

type ErrorCode int32
const (
	// ErrorCodeUnknown 90xx.
	ErrorCodeUnknown ErrorCode = 9000

	// ErrorCodeInvalidRequest 91xx.
	ErrorCodeInvalidRequest          ErrorCode = 9100
	ErrorCodeInvalidArgument         ErrorCode = 9101
	ErrorCodeCESQLExpression         ErrorCode = 9102
	ErrorCodeCELExpression           ErrorCode = 9103
	ErrorCodeFilterAttributeIsEmpty  ErrorCode = 9104
	ErrorCodeFilterMultiple          ErrorCode = 9105
	ErrorCodeInvalidHeartbeatRequest ErrorCode = 9106
	ErrorCodeJSONParse               ErrorCode = 9107
	ErrorCodeTransformInputParse     ErrorCode = 9108
	ErrorCodeCorruptedEvent          ErrorCode = 9109

	// ErrorCodeServiceNotRunning 92xx.
	ErrorCodeServiceNotRunning         ErrorCode = 9200
	ErrorCodeSegmentServerHasBeenAdded ErrorCode = 9201
	ErrorCodeServiceStateError         ErrorCode = 9202
	ErrorCodeWorkerNotRunning          ErrorCode = 9203

	// ErrorCodeResourceExist 93xx
	ErrorCodeResourceExist ErrorCode = 9300

	// ErrorCodeResourceNotFound 94xx.
	ErrorCodeResourceNotFound ErrorCode = 9400
	ErrorCodeEventbusNotFound ErrorCode = 9401
	ErrorCodeEventlogNotFound ErrorCode = 9402
	ErrorCodeSegmentNotFound  ErrorCode = 9403
	ErrorCodeBlockNotFound    ErrorCode = 9404
	ErrorCodeVolumeNotFound   ErrorCode = 9405

	// ErrorCodeInternal 95xx.
	ErrorCodeInternal             ErrorCode = 9500
	ErrorCodeTriggerWorker        ErrorCode = 9501
	ErrorCodeInvalidSegment       ErrorCode = 9502
	ErrorCodeInvalidHeartbeat     ErrorCode = 9503
	ErrorCodeVolumeNoServer       ErrorCode = 9504
	ErrorCodeJSONMarshal          ErrorCode = 9505
	ErrorCodeJSONUnmarshal        ErrorCode = 9506
	ErrorCodeAESEncrypt           ErrorCode = 9507
	ErrorCodeAESDecrypt           ErrorCode = 9508
	ErrorCodeUnmarshal            ErrorCode = 9509
	ErrorCodeLambdaInvoke         ErrorCode = 9510
	ErrorCodeLambdaInvokeResponse ErrorCode = 9511
	ErrorCodeInvalidJSONPath      ErrorCode = 9512
	ErrorCodeJSONPathNotExist     ErrorCode = 9513

	// ErrorCodeSegmentFull 96xx.
	ErrorCodeSegmentFull          ErrorCode = 9600
	ErrorCodeSegmentNoEnoughSpace ErrorCode = 9601
	ErrorCodeOffsetUnderflow      ErrorCode = 9602
	ErrorCodeOffsetOverflow       ErrorCode = 9603
	ErrorCodeOffsetOnEnd          ErrorCode = 9604
	ErrorCodeBlockNotSupported    ErrorCode = 9605
	ErrorCodeNotWritable          ErrorCode = 9606
	ErrorCodeNotReadable          ErrorCode = 9607
	ErrorCodeTryAgain             ErrorCode = 9608
	ErrorCodeNoEndpoint           ErrorCode = 9609
	ErrorCodeClosed               ErrorCode = 9610

	// ErrorCodeNotLeader 97xx.
	ErrorCodeNotLeader          ErrorCode = 9700
	ErrorCodeNoControllerLeader ErrorCode = 9701
	ErrorCodeNotRaftLeader      ErrorCode = 9702
	ErrorCodeNotReady           ErrorCode = 9704

	// ErrorCode_OTHERS 99xx.
	ErrorCodeResourceExhausted ErrorCode = 9901
	ErrorCodeResourceCanNotOp  ErrorCode = 9902

	ErrorCodeUnauthenticated  ErrorCode = 9910
	ErrorCodePermissionDenied ErrorCode = 9911
)

type ErrorType

type ErrorType struct {
	Description string    `json:"description"`
	Message     string    `json:"message"`
	Code        ErrorCode `json:"code"`
	// contains filtered or unexported fields
}

func Convert

func Convert(str string) (*ErrorType, bool)

func FromError

func FromError(err error) (*ErrorType, bool)

func New

func New(desc string) *ErrorType

func (ErrorType) Error

func (e ErrorType) Error() string

Error return readable error message by JSON format

func (*ErrorType) JSON

func (e *ErrorType) JSON() string

func (*ErrorType) WithGRPCCode

func (e *ErrorType) WithGRPCCode(c ErrorCode) *ErrorType

func (*ErrorType) WithMessage

func (e *ErrorType) WithMessage(str string) *ErrorType

WithMessage add additional message to explain what try to do cause this error. the explanation was used to improve understandability of the error in order to make people know what they should do

func (*ErrorType) Wrap

func (e *ErrorType) Wrap(err error) *ErrorType

Wrap the other error as the underlay errors of this error. sometimes we return an error because of another error(named underlay error). So, we should add the underlay error to this error's context. By this, the people can understand why this error they received

Jump to

Keyboard shortcuts

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