errors

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors defines flexitype's typed domain errors. Interface layers map Code onto their transport (HTTP status, gRPC code); usecases and domain code create errors through the constructors so every failure carries a stable machine-readable code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetailsOf

func DetailsOf(err error) map[string]any

DetailsOf returns the structured details of a domain error, or nil.

func IsArchived

func IsArchived(err error) bool

IsArchived reports whether err carries CodeArchived.

func IsConflict

func IsConflict(err error) bool

IsConflict reports whether err carries CodeConflict.

func IsDependencyViolation

func IsDependencyViolation(err error) bool

IsDependencyViolation reports whether err carries CodeDependency.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err carries CodeNotFound.

func IsValidation

func IsValidation(err error) bool

IsValidation reports whether err carries CodeValidation.

Types

type Code

type Code string

Code classifies a domain failure.

const (
	// CodeValidation marks malformed or rule-violating input.
	CodeValidation Code = "VALIDATION"
	// CodeNotFound marks a missing aggregate.
	CodeNotFound Code = "NOT_FOUND"
	// CodeConflict marks uniqueness or concurrency conflicts.
	CodeConflict Code = "CONFLICT"
	// CodeArchived marks mutations against archived aggregates.
	CodeArchived Code = "ARCHIVED"
	// CodeDependency marks values rejected by an attribute dependency.
	CodeDependency Code = "DEPENDENCY_VIOLATION"
	// CodeForbidden marks an action the principal is not permitted to take
	// (e.g. writing a field their permission set denies).
	CodeForbidden Code = "FORBIDDEN"
)

func CodeOf

func CodeOf(err error) Code

CodeOf extracts the domain code from err, or "" when err is not a domain error.

type Error

type Error struct {
	Code    Code
	Message string
	Details map[string]any
}

Error is a typed domain error with structured details.

func NewArchived

func NewArchived(entity, id string) *Error

NewArchived builds a CodeArchived error for an entity/ID pair.

func NewConflict

func NewConflict(message string, kv ...any) *Error

NewConflict builds a CodeConflict error.

func NewDependencyViolation

func NewDependencyViolation(message string, kv ...any) *Error

NewDependencyViolation builds a CodeDependency error.

func NewForbidden

func NewForbidden(message string, kv ...any) *Error

NewForbidden builds a CodeForbidden error.

func NewNotFound

func NewNotFound(entity, id string) *Error

NewNotFound builds a CodeNotFound error for an entity/ID pair.

func NewValidation

func NewValidation(message string, kv ...any) *Error

NewValidation builds a CodeValidation error. Details are optional key/value pairs: NewValidation("bad name", "name", got).

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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