commonerrors

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package commonerrors providers errors shared by all handlers.

Index

Constants

View Source
const (

	// ErrBadValue indicates wrong input.
	ErrBadValue = ErrorCode(2) // BadValue

	// ErrFailedToParse indicates user input parsing failure.
	ErrFailedToParse = ErrorCode(9) // FailedToParse

	// ErrTypeMismatch for $sort indicates that the expression in the $sort is not an object.
	ErrTypeMismatch = ErrorCode(14) // TypeMismatch

	// ErrNamespaceNotFound indicates that a collection is not found.
	ErrNamespaceNotFound = ErrorCode(26) // NamespaceNotFound

	// ErrUnsuitableValueType indicates that field could not be created for given value.
	ErrUnsuitableValueType = ErrorCode(28) // UnsuitableValueType

	// ErrConflictingUpdateOperators indicates that $set, $inc or $setOnInsert were used together.
	ErrConflictingUpdateOperators = ErrorCode(40) // ConflictingUpdateOperators

	// ErrNamespaceExists indicates that the collection already exists.
	ErrNamespaceExists = ErrorCode(48) // NamespaceExists

	// ErrInvalidID indicates that _id field is invalid.
	ErrInvalidID = ErrorCode(53) // InvalidID

	// ErrEmptyName indicates that the field name is empty.
	ErrEmptyName = ErrorCode(56) // EmptyName

	// ErrCommandNotFound indicates unknown command input.
	ErrCommandNotFound = ErrorCode(59) // CommandNotFound

	// ErrInvalidNamespace indicates that the collection name is invalid.
	ErrInvalidNamespace = ErrorCode(73) // InvalidNamespace

	// ErrOperationFailed indicates that the operation failed.
	ErrOperationFailed = ErrorCode(96) // OperationFailed

	// ErrDocumentValidationFailure indicates that document validation failed.
	ErrDocumentValidationFailure = ErrorCode(121) // DocumentValidationFailure

	// ErrNotImplemented indicates that a flag or command is not implemented.
	ErrNotImplemented = ErrorCode(238) // NotImplemented

	// ErrMechanismUnavailable indicates unsupported authentication mechanism.
	ErrMechanismUnavailable = ErrorCode(334) // MechanismUnavailable

	// ErrSortBadValue indicates bad value in sort input.
	ErrSortBadValue = ErrorCode(15974) // Location15974

	// ErrSortBadOrder indicates bad sort order input.
	ErrSortBadOrder = ErrorCode(15975) // Location15975

	// ErrInvalidArg indicates invalid argument in projection document.
	ErrInvalidArg = ErrorCode(28667) // Location28667

	// ErrSliceFirstArg for $slice indicates that the first argument is not an array.
	ErrSliceFirstArg = ErrorCode(28724) // Location28724

	// ErrProjectionInEx for $elemMatch indicates that inclusion statement found
	// while projection document already marked as exlusion.
	ErrProjectionInEx = ErrorCode(31253) // Location31253

	// ErrProjectionExIn for $elemMatch indicates that exlusion statement found
	// while projection document already marked as inclusion.
	ErrProjectionExIn = ErrorCode(31254) // Location31254

	// ErrStageCountNonEmptyString indicates that $count aggregation stage expected non-empty string.
	ErrStageCountNonEmptyString = ErrorCode(40156) // Location40156

	// ErrStageInvalid indicates invalid aggregation pipeline stage.
	ErrStageInvalid = ErrorCode(40323) // Location40323

	// ErrEmptyFieldPath indicates that the field path is empty.
	ErrEmptyFieldPath = ErrorCode(40352) // Location40352

	// ErrMissingField indicates that the required field in document is missing.
	ErrMissingField = ErrorCode(40414) // Location40414

	// ErrFailedToParseInput indicates invalid input (absent or malformed fields).
	ErrFailedToParseInput = ErrorCode(40415) // Location40415

	// ErrFreeMonitoringDisabled indicates that free monitoring is disabled
	// by command-line or config file.
	ErrFreeMonitoringDisabled = ErrorCode(50840) // Location50840

	// ErrRegexOptions indicates regex options error.
	ErrRegexOptions = ErrorCode(51075) // Location51075

	// ErrRegexMissingParen indicates missing parentheses in regex expression.
	ErrRegexMissingParen = ErrorCode(51091) // Location51091

	// ErrBadRegexOption indicates bad regex option value passed.
	ErrBadRegexOption = ErrorCode(51108) // Location51108
)

Variables

This section is empty.

Functions

func CheckError

func CheckError(err error) error

CheckError checks error type and returns properly translated error.

func NewCommandError

func NewCommandError(code ErrorCode, err error) error

NewCommandError creates a new wire protocol error.

Code shouldn't be zero, err can't be nil.

func NewCommandErrorMsg

func NewCommandErrorMsg(code ErrorCode, msg string) error

NewCommandErrorMsg is variant for NewCommandError with error string.

Code shouldn't be zero, err can't be empty.

func NewCommandErrorMsgWithArgument

func NewCommandErrorMsgWithArgument(code ErrorCode, msg string, argument string) error

NewCommandErrorMsgWithArgument creates a new wire protocol error with an argument that caused the error.

func NewWriteErrorMsg

func NewWriteErrorMsg(code ErrorCode, msg string) error

NewWriteErrorMsg creates a new protocol write error with given ErrorCode and message.

Types

type CommandError

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

CommandError represents wire protocol command error.

func (*CommandError) Code

func (e *CommandError) Code() ErrorCode

Code implements ProtoErr interface.

func (*CommandError) Document

func (e *CommandError) Document() *types.Document

Document implements ProtoErr interface.

func (*CommandError) Error

func (e *CommandError) Error() string

Error implements error interface.

func (*CommandError) Info

func (e *CommandError) Info() *ErrInfo

Info implements ProtoErr interface.

func (*CommandError) Unwrap

func (e *CommandError) Unwrap() error

Unwrap implements ProtoErr interface.

type ErrInfo

type ErrInfo struct {
	Argument string // command's argument, operator, or aggregation pipeline stage that caused an error
}

ErrInfo represents additional optional error information.

type ErrorCode

type ErrorCode int32

ErrorCode represents wire protocol error code.

func (ErrorCode) String

func (i ErrorCode) String() string

type ProtoErr

type ProtoErr interface {
	error
	// Unwrap returns unwrapped error.
	Unwrap() error
	// Code returns ErrorCode.
	Code() ErrorCode
	// Document returns *types.Document.
	Document() *types.Document
	// Info returns *ErrInfo.
	Info() *ErrInfo
}

ProtoErr represents protocol error type.

func ProtocolError

func ProtocolError(err error) (ProtoErr, bool)

ProtocolError converts any error to wire protocol error.

Nil panics, *CommandError or *WriteErrors (possibly wrapped) is returned unwrapped with true, any other value is wrapped with InternalError and returned with false.

type WriteErrors

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

WriteErrors represents a slice of protocol write errors. It could be returned for Update, Insert, Delete, and Replace operations.

func (*WriteErrors) Append

func (we *WriteErrors) Append(err error, index int32)

Append converts the err to the writeError type and appends it to WriteErrors. The index value is an index of the query with error.

func (*WriteErrors) Code

func (we *WriteErrors) Code() ErrorCode

Code implements ProtoErr interface.

func (*WriteErrors) Document

func (we *WriteErrors) Document() *types.Document

Document implements ProtoErr interface.

func (*WriteErrors) Error

func (we *WriteErrors) Error() string

Error implements error interface.

func (*WriteErrors) Info

func (we *WriteErrors) Info() *ErrInfo

Info implements ProtoErr interface.

func (*WriteErrors) Len

func (we *WriteErrors) Len() int

Len returns the number of errors.

func (*WriteErrors) Merge

func (we *WriteErrors) Merge(we2 *WriteErrors, index int32)

Merge merges the given WriteErrors with the current one and sets the given index.

func (*WriteErrors) Unwrap

func (we *WriteErrors) Unwrap() error

Unwrap implements ProtoErr interface.

Jump to

Keyboard shortcuts

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