fabriqerr

package
v0.0.6 Latest Latest
Warning

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

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

Documentation

Overview

Package fabriqerr holds the canonical shared error values used across fabriq's core packages. The root fabriq package aliases everything here (fabriq.ErrNotFound, fabriq.VersionConflictError, ...) — application code should depend on those aliases; core and adapter packages depend on this leaf so the dependency direction stays root -> core.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound: aggregate or row absent within the tenant's scope.
	ErrNotFound = errors.New("fabriq: not found")

	// ErrVersionConflict: optimistic-concurrency mismatch.
	ErrVersionConflict = errors.New("fabriq: version conflict")

	// ErrProjectionLag: WaitForProjection deadline expired.
	ErrProjectionLag = errors.New("fabriq: projection lagging")

	// ErrStoreNotConfigured: capability port without a configured backend.
	ErrStoreNotConfigured = errors.New("fabriq: store not configured")

	// ErrQueryTimeout is returned when a query exceeds its time budget — the
	// statement_timeout fires (pg SQLSTATE 57014) or the context deadline is hit.
	ErrQueryTimeout = errors.New("fabriq: query exceeded the time limit")

	// ErrRawSQLUnsupported is returned by RelationalQuerier.Query on backends
	// that have no raw-SQL escape hatch (e.g. the in-memory test fake).
	// Callers may fall back to portable reads built from List/Get instead.
	ErrRawSQLUnsupported = errors.New("fabriq: relational backend does not execute raw SQL")
)

Functions

func SafeMessage added in v0.0.4

func SafeMessage(code Code) string

SafeMessage returns the default caller-facing message for a Code. Callers that have nothing more specific to say pass this to New/Wrap.

Types

type Code added in v0.0.4

type Code string

Code is a stable, machine-readable error category. Every driver and layer maps its failures into one of these; HTTP and RPC boundaries switch on Code rather than matching on error-message substrings.

const (
	CodeNotFound            Code = "not_found"
	CodeAlreadyExists       Code = "already_exists"
	CodeConstraintViolation Code = "constraint_violation"
	CodeSchemaMismatch      Code = "schema_mismatch"
	CodeInvalidInput        Code = "invalid_input"
	CodeVersionConflict     Code = "version_conflict"
	CodeUnauthorized        Code = "unauthorized"
	CodePermissionDenied    Code = "permission_denied"
	CodeUnavailable         Code = "unavailable"
	CodeTimeout             Code = "timeout"
	CodeSerialization       Code = "serialization"
	CodeNotConfigured       Code = "not_configured"
	CodeInternal            Code = "internal"
)

func CodeOf added in v0.0.6

func CodeOf(err error) Code

CodeOf extracts the structured code from an error chain ("" when the chain carries no *Error) — the classification seam callers use to map errors onto transport statuses without unwrapping by hand.

type Error added in v0.0.4

type Error struct {
	Code      Code   `json:"code"`
	Message   string `json:"message"`
	Entity    string `json:"entity,omitempty"`
	ID        string `json:"id,omitempty"`
	Op        string `json:"op,omitempty"`
	Meta      Meta   `json:"meta,omitempty"`
	Retryable bool   `json:"retryable"`
	// contains filtered or unexported fields
}

Error is fabriq's canonical structured error. Message is always safe to show a caller and never contains driver text; the underlying driver error is kept as cause (reachable via errors.As / Unwrap) but never serialized as-is.

func New added in v0.0.4

func New(code Code, msg string, opts ...Option) *Error

New builds a structured error with no wrapped cause.

func Wrap added in v0.0.4

func Wrap(code Code, cause error, msg string, opts ...Option) *Error

Wrap builds a structured error carrying cause (reachable via Unwrap).

func (*Error) Error added in v0.0.4

func (e *Error) Error() string

func (*Error) Is added in v0.0.4

func (e *Error) Is(target error) bool

Is maps the structured Code back onto the package sentinels so existing errors.Is(err, ErrNotFound) / ErrVersionConflict / ErrStoreNotConfigured checks keep working.

func (*Error) Unwrap added in v0.0.4

func (e *Error) Unwrap() error

Unwrap exposes the wrapped driver cause for logging and errors.As, without ever placing it in the caller-facing message.

type Meta added in v0.0.4

type Meta struct {
	Driver     string            `json:"driver,omitempty"`
	SQLState   string            `json:"sqlstate,omitempty"`
	Constraint string            `json:"constraint,omitempty"`
	Table      string            `json:"table,omitempty"`
	Column     string            `json:"column,omitempty"`
	Detail     map[string]string `json:"detail,omitempty"`
}

Meta carries structured, driver-native detail. Fields are decomposed (never a raw driver dump); Detail holds driver-specific extras with no typed slot.

type NotFoundError

type NotFoundError struct {
	Entity string
	ID     string
}

NotFoundError reports a missing aggregate within the tenant's scope.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (*NotFoundError) Is

func (e *NotFoundError) Is(target error) bool

Is makes errors.Is(err, ErrNotFound) match.

type Option added in v0.0.4

type Option func(*Error)

Option configures an Error at construction.

func WithCause added in v0.0.4

func WithCause(err error) Option

func WithEntity added in v0.0.4

func WithEntity(entity, id string) Option

func WithMeta added in v0.0.4

func WithMeta(m Meta) Option

func WithOp added in v0.0.4

func WithOp(op string) Option

func WithRetryable added in v0.0.4

func WithRetryable(r bool) Option

type VersionConflictError

type VersionConflictError struct {
	Aggregate string
	AggID     string
	Expected  int64
	Actual    int64
}

VersionConflictError reports an optimistic-concurrency failure.

func (*VersionConflictError) Error

func (e *VersionConflictError) Error() string

func (*VersionConflictError) Is

func (e *VersionConflictError) Is(target error) bool

Is makes errors.Is(err, ErrVersionConflict) match.

Jump to

Keyboard shortcuts

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