errors

package
v0.0.0-...-d364ca2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package errors defines stable errors shared by Soro's non-HTTP layers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCode

func IsCode(err error, code Code) bool

IsCode reports whether err contains a Soro error with code.

Types

type Code

type Code string

Code identifies a category of framework error without exposing its cause.

const (
	CodeNotFound        Code = "not_found"
	CodeValidation      Code = "validation_failed"
	CodeConflict        Code = "conflict"
	CodeForbidden       Code = "forbidden"
	CodeUnauthorized    Code = "unauthorized"
	CodeInternal        Code = "internal_error"
	CodeInvalidArgument Code = "invalid_argument"
	CodeInvalidQuery    Code = "invalid_query"
)

type Error

type Error struct {
	Code      Code                `json:"code"`
	Message   string              `json:"message"`
	RequestID string              `json:"request_id,omitempty"`
	Fields    map[string][]string `json:"fields,omitempty"`
	// contains filtered or unexported fields
}

Error is safe to serialize. Cause is deliberately omitted from JSON.

func Conflict

func Conflict(message string) *Error

func FieldError

func FieldError(field, message string) *Error

FieldError adds one normalized message for a field.

func Forbidden

func Forbidden(message string) *Error

func Internal

func Internal(cause error) *Error

func InvalidArgument

func InvalidArgument(message string) *Error

func InvalidQuery

func InvalidQuery(message string) *Error

func NotFound

func NotFound(resource string) *Error

func Unauthorized

func Unauthorized(message string) *Error

func Validation

func Validation(fields map[string][]string) *Error

func Wrap

func Wrap(code Code, message string, cause error) *Error

Wrap annotates an internal cause while retaining a safe public message.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap preserves the internal cause for errors.Is/errors.As and logging.

func (*Error) WithCause

func (e *Error) WithCause(cause error) *Error

WithCause attaches an internal error without making it serializable.

Jump to

Keyboard shortcuts

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