errors

package
v0.0.0-...-11f3bbb Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PgErrDuplicateKey = "23505"
)

postgres error codes

View Source
const (

	// SVC prefix for error codes
	SVC string = "API"
)

Variables

View Source
var AuthErrorCodes = map[ErrorCode]struct{}{
	ErrTokenExpiredInvalid:    {},
	ErrAuthInvalidCredentials: {},
	ErrAuthMissingToken:       {},
}

Map of auth error codes

Map of forbidden error codes

Map of server-side error codes that need to be filtered

Functions

func EnrichWithCtx

func EnrichWithCtx(ctx context.Context, ae *AppError)

Sets `ExtraData` from context in the app error

func GetHTTPStatusCode

func GetHTTPStatusCode(code ErrorCode) int

func GetSrcFromCtx

func GetSrcFromCtx(ctx context.Context) string

Extracts `Src` from the given context

func GetStackTrace

func GetStackTrace() string

GetStackTrace returns a human-readable stack trace

func IsAuthErrorCode

func IsAuthErrorCode(code ErrorCode) bool

IsAuthErrorCode checks if the error is an auth error

func IsForbiddenErrorCode

func IsForbiddenErrorCode(code ErrorCode) bool

IsForbiddenErrorCode checks if the error is a forbidden error

func IsSameError

func IsSameError(err error, code ErrorCode) bool

IsSameError checks if the error is the same as the given ErrorCode

func IsServerErrorCode

func IsServerErrorCode(code ErrorCode) bool

IsServerErrorCode checks if the error is a server-side error

func Raise

func Raise(ctx context.Context, code ErrorCode, msg string, errToWrap error, extraData common.ExtraData) error

Raise is a general util to construct domain errors

func RaiseInternal

func RaiseInternal(ctx context.Context, msg string, errToWrap error, extraData common.ExtraData) error

RaiseInternal raises an internal error

func RaiseToSentry

func RaiseToSentry(ctx context.Context, err error)

RaiseToSentry raises the error to Sentry

func RecoverPanic

func RecoverPanic(msg string) func()

RecoverPanic can be deferred to capture and log a panic

func SetSrcInCtx

func SetSrcInCtx(ctx context.Context, src string) context.Context

Sets `Src` in the given context.

Types

type AppError

type AppError struct {
	ErrorCode ErrorCode        // unique error code
	Message   string           // optional human-readable message
	Cause     error            // wrapped error
	ExtraData common.ExtraData // extra data associated with the error
}

AppError represents an application error with a code, message, cause, and extra data

func AsAppError

func AsAppError(err error) (*AppError, bool)

AsAppError tries to cast the given error to an AppError

func (*AppError) AddExtraData

func (ae *AppError) AddExtraData(key string, val any)

func (*AppError) Error

func (ae *AppError) Error() string

func (*AppError) Format

func (ae *AppError) Format(s fmt.State, verb rune)

func (*AppError) GetCode

func (ae *AppError) GetCode() string

func (*AppError) GetErrorCode

func (ae *AppError) GetErrorCode() ErrorCode

func (*AppError) GetExtraData

func (ae *AppError) GetExtraData() common.ExtraData

func (*AppError) GetMessage

func (ae *AppError) GetMessage() string

func (*AppError) Unwrap

func (ae *AppError) Unwrap() error

type ErrorCode

type ErrorCode string

ErrorCode type

const (
	// System errors
	ErrInternalError  ErrorCode = "SYS-00"
	ErrMarshalError   ErrorCode = "SYS-01"
	ErrUnmarshalError ErrorCode = "SYS-02"

	// Validation errors
	ErrValidationFailed ErrorCode = "VAL-00"

	// Rest errors
	ErrRestInvalidPayload ErrorCode = "REST-00"
	ErrRestMissingToken   ErrorCode = "REST-01"
	ErrRestTimedOut       ErrorCode = "REST-02"

	// User errors
	ErrUserInvalidRole     ErrorCode = "USER-00"
	ErrUserEmailTaken      ErrorCode = "USER-01"
	ErrUserUsernameTaken   ErrorCode = "USER-02"
	ErrUserNotFound        ErrorCode = "USER-03"
	ErrUserInsufficentRole ErrorCode = "USER-04"

	// Team errors
	ErrTeamRequired      ErrorCode = "TEAM-00"
	ErrTeamAlreadyJoined ErrorCode = "TEAM-01"
	ErrTeamNameTaken     ErrorCode = "TEAM-02"
	ErrTeamNotFound      ErrorCode = "TEAM-03"
	ErrTeamFull          ErrorCode = "TEAM-04"

	// DB errors
	ErrDBCreateError ErrorCode = "DB-00"
	ErrDBReadError   ErrorCode = "DB-01"
	ErrDBUpdateError ErrorCode = "DB-02"
	ErrDBExecError   ErrorCode = "DB-03"
	ErrDBDeleteError ErrorCode = "DB-04"

	// Cache errors
	ErrCacheCallFail          ErrorCode = "CACHE-00"
	ErrCacheMiss              ErrorCode = "CACHE-01"
	ErrCacheScriptLoadFail    ErrorCode = "CACHE-02"
	ErrCacheZSetMissingMember ErrorCode = "CACHE-03"

	// Token errors
	ErrTokenMalformed      ErrorCode = "TOKEN-00"
	ErrTokenExpiredInvalid ErrorCode = "TOKEN-01"
	ErrTokenSigningFailed  ErrorCode = "TOKEN-02"

	// ConfigVar errors
	ErrConfigVarInvalid       ErrorCode = "CONFIGVAR-00"
	ErrConfigVarRefreshFailed ErrorCode = "CONFIGVAR-01"

	// SMTP errors
	ErrSMTPDialError          ErrorCode = "SMTP-00"
	ErrSMTPQueueFull          ErrorCode = "SMTP-01"
	ErrSMTPMaxRetriesExceeded ErrorCode = "SMTP-02"
	ErrSMTPSendFailed         ErrorCode = "SMTP-03"
	ErrSMTPContextCanceled    ErrorCode = "SMTP-04"

	// Email errors
	ErrEmailInvalidType     ErrorCode = "EMAIL-00"
	ErrEmailTemplateFetch   ErrorCode = "EMAIL-01"
	ErrEmailTemplateExecute ErrorCode = "EMAIL-02"
	ErrEmailLinkBuild       ErrorCode = "EMAIL-03"

	// Auth errors
	ErrAuthInvalidCredentials    ErrorCode = "AUTH-00"
	ErrAuthMaxSessionsReached    ErrorCode = "AUTH-01"
	ErrAuthPasswordResetDisabled ErrorCode = "AUTH-02"
	ErrAuthMissingToken          ErrorCode = "AUTH-03"
	ErrAuthUserBanned            ErrorCode = "AUTH-04"

	// Challenge errors
	ErrChallengeNotFound           ErrorCode = "CHALLENGE-00"
	ErrChallengeAlreadySolved      ErrorCode = "CHALLENGE-01"
	ErrChallengeMaxAttemptsReached ErrorCode = "CHALLENGE-02"
	ErrChallengeNameInvalid        ErrorCode = "CHALLENGE-03"

	// Hint errors
	ErrHintNotFound        ErrorCode = "HINT-00"
	ErrHintCostExceeded    ErrorCode = "HINT-01"
	ErrHintAlreadyUnlocked ErrorCode = "HINT-02"

	// Scoreboard errors
	ErrScoreUpdateFailed ErrorCode = "SCORE-00"

	// Instance errors
	ErrInstanceNotOnDemand             ErrorCode = "INSTANCE-00"
	ErrInstanceNotFound                ErrorCode = "INSTANCE-01"
	ErrInstanceWIP                     ErrorCode = "INSTANCE-02"
	ErrInstanceAlreadyRunning          ErrorCode = "INSTANCE-03"
	ErrInstanceCreationFailed          ErrorCode = "INSTANCE-04"
	ErrInstanceInvalid                 ErrorCode = "INSTANCE-05"
	ErrInstanceInvalidResourceQuantity ErrorCode = "INSTANCE-06"
	ErrInstanceExtensionNotAllowed     ErrorCode = "INSTANCE-07"
	ErrInstanceUpdateFailed            ErrorCode = "INSTANCE-08"
	ErrInstanceDeletionFailed          ErrorCode = "INSTANCE-09"
	ErrInstanceInvalidState            ErrorCode = "INSTANCE-10"
	ErrInstanceNotRunning              ErrorCode = "INSTANCE-11"

	// k8s errors
	ErrK8sConnectionFailed ErrorCode = "K8S-00"

	// Manifest errors
	ErrManifestNotFound ErrorCode = "MANIFEST-00"
)

Error codes

func ExtractErrorCode

func ExtractErrorCode(err error) (ErrorCode, bool)

ExtractErrorCode extracts the ErrorCode from an error, if it is an AppError

Jump to

Keyboard shortcuts

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