Documentation
¶
Index ¶
- Constants
- Variables
- func As(err error, target any) bool
- func HTTPStatusFromErr(err error) int
- func IsAlreadyExists(err error) bool
- func IsDatabase(err error) bool
- func IsHTTPClient(err error) bool
- func IsInternal(err error) bool
- func IsInvalidOperation(err error) bool
- func IsNotFound(err error) bool
- func IsPermissionDenied(err error) bool
- func IsSystem(err error) bool
- func IsValidation(err error) bool
- func IsVersionConflict(err error) bool
- type ErrorBuilder
- func (b *ErrorBuilder) Error() error
- func (b *ErrorBuilder) Mark(reference error) error
- func (b *ErrorBuilder) WithHint(hint string) *ErrorBuilder
- func (b *ErrorBuilder) WithHintf(format string, args ...any) *ErrorBuilder
- func (b *ErrorBuilder) WithMessage(msg string) *ErrorBuilder
- func (b *ErrorBuilder) WithMessagef(format string, args ...any) *ErrorBuilder
- func (b *ErrorBuilder) WithReportableDetails(details map[string]any) *ErrorBuilder
- type ErrorDetail
- type ErrorResponse
- type InternalError
Constants ¶
const ( ErrCodeHTTPClient = "http_client_error" ErrCodeSystemError = "system_error" ErrCodeInternalError = "internal_error" ErrCodeNotFound = "not_found" ErrCodeAlreadyExists = "already_exists" ErrCodeVersionConflict = "version_conflict" ErrCodeValidation = "validation_error" ErrCodeInvalidOperation = "invalid_operation" ErrCodePermissionDenied = "permission_denied" ErrCodeDatabase = "database_error" )
Variables ¶
var ( ErrNotFound = new(ErrCodeNotFound, "resource not found") ErrAlreadyExists = new(ErrCodeAlreadyExists, "resource already exists") ErrVersionConflict = new(ErrCodeVersionConflict, "version conflict") ErrValidation = new(ErrCodeValidation, "validation error") ErrInvalidOperation = new(ErrCodeInvalidOperation, "invalid operation") ErrPermissionDenied = new(ErrCodePermissionDenied, "permission denied") ErrHTTPClient = new(ErrCodeHTTPClient, "http client error") ErrDatabase = new(ErrCodeDatabase, "database error") ErrSystem = new(ErrCodeSystemError, "system error") ErrInternal = new(ErrCodeInternalError, "internal error") )
Common error types that can be used across the application TODO: move to errors.New from cockroachdb/errors
Functions ¶
func HTTPStatusFromErr ¶
func IsAlreadyExists ¶
IsAlreadyExists checks if an error is an already exists error
func IsDatabase ¶ added in v1.0.0
func IsHTTPClient ¶
IsHTTPClient checks if an error is an http client error
func IsInternal ¶ added in v1.0.17
func IsInvalidOperation ¶
IsInvalidOperation checks if an error is an invalid operation error
func IsNotFound ¶
IsNotFound checks if an error is a not found error
func IsPermissionDenied ¶
IsPermissionDenied checks if an error is a permission denied error
func IsValidation ¶
IsValidation checks if an error is a validation error
func IsVersionConflict ¶
IsVersionConflict checks if an error is a version conflict error
Types ¶
type ErrorBuilder ¶
type ErrorBuilder struct {
// contains filtered or unexported fields
}
ErrorBuilder provides a fluent interface for building errors but does not implement the error interface. This is intentional. Mark must be the last call in the chain when using the builder.
func NewErrorf ¶ added in v1.0.13
func NewErrorf(format string, args ...any) *ErrorBuilder
func WithError ¶
func WithError(err error) *ErrorBuilder
WithError starts a builder chain with an existing error
func (*ErrorBuilder) Mark ¶
func (b *ErrorBuilder) Mark(reference error) error
Mark marks the error with a sentinel error should be the last call in the chain
func (*ErrorBuilder) WithHint ¶
func (b *ErrorBuilder) WithHint(hint string) *ErrorBuilder
WithHint adds context to the error this is for the frontend error messages
func (*ErrorBuilder) WithHintf ¶
func (b *ErrorBuilder) WithHintf(format string, args ...any) *ErrorBuilder
WithHintf is a helper for WithHint that allows for formatting
func (*ErrorBuilder) WithMessage ¶
func (b *ErrorBuilder) WithMessage(msg string) *ErrorBuilder
WithMessage adds context to the error this is for the internal error messages
func (*ErrorBuilder) WithMessagef ¶ added in v1.0.0
func (b *ErrorBuilder) WithMessagef(format string, args ...any) *ErrorBuilder
func (*ErrorBuilder) WithReportableDetails ¶
func (b *ErrorBuilder) WithReportableDetails(details map[string]any) *ErrorBuilder
WithReportableDetails adds structured details
type ErrorDetail ¶
type ErrorDetail struct {
Display string `json:"message"`
InternalError string `json:"internal_error,omitempty"`
Details map[string]any `json:"details,omitempty" swaggerignore:"true"`
}
ErrorDetail contains error information
type ErrorResponse ¶
type ErrorResponse struct {
Success bool `json:"success"`
Error ErrorDetail `json:"error"`
}
ErrorResponse represents the standard error response structure
type InternalError ¶
type InternalError struct {
Code string // Machine-readable error code
Message string // Human-readable error message
Op string // Logical operation name
Err error // Underlying error
}
InternalError represents a domain error
func (*InternalError) DisplayError ¶
func (e *InternalError) DisplayError() string
func (*InternalError) Error ¶
func (e *InternalError) Error() string
func (*InternalError) Is ¶
func (e *InternalError) Is(target error) bool
Is implements error matching for wrapped errors
func (*InternalError) Unwrap ¶
func (e *InternalError) Unwrap() error