semantic.go

v0.2.0
Doc Versions Source
1
package culpa
2
3
import "log/slog"
4
5
// IllegalState signals an operation invoked in a wrong state.
6
type IllegalState struct{}
7
8
func (IllegalState) Error() string        { return "illegal state" }
9
func (IllegalState) LogValue() slog.Value { return slog.StringValue("illegal state") }
10
11
// IllegalValue signals a value that failed a precondition or invariant.
12
type IllegalValue struct{}
13
14
func (IllegalValue) Error() string        { return "illegal value" }
15
func (IllegalValue) LogValue() slog.Value { return slog.StringValue("illegal value") }
16
17
// Impossible signals a code path that should never be reached (bug).
18
type Impossible struct{}
19
20
func (Impossible) Error() string        { return "impossible" }
21
func (Impossible) LogValue() slog.Value { return slog.StringValue("impossible") }
22
23
// NotImplemented signals an operation that exists but has no implementation yet.
24
type NotImplemented struct{}
25
26
func (NotImplemented) Error() string        { return "not implemented" }
27
func (NotImplemented) LogValue() slog.Value { return slog.StringValue("not implemented") }
28
29
// Unsupported signals an operation intentionally not supported.
30
type Unsupported struct{}
31
32
func (Unsupported) Error() string        { return "unsupported" }
33
func (Unsupported) LogValue() slog.Value { return slog.StringValue("unsupported") }
34
35
// NewIllegalState creates an IllegalState error with a captured stacktrace.
36
func NewIllegalState() error { return withStacktrace(&culpaError{cause: IllegalState{}}) }
37
38
// NewIllegalValue creates an IllegalValue error with a captured stacktrace.
39
func NewIllegalValue() error { return withStacktrace(&culpaError{cause: IllegalValue{}}) }
40
41
// NewImpossible creates an Impossible error with a captured stacktrace.
42
func NewImpossible() error { return withStacktrace(&culpaError{cause: Impossible{}}) }
43
44
// NewNotImplemented creates a NotImplemented error with a captured stacktrace.
45
func NewNotImplemented() error { return withStacktrace(&culpaError{cause: NotImplemented{}}) }
46
47
// NewUnsupported creates an Unsupported error with a captured stacktrace.
48
func NewUnsupported() error { return withStacktrace(&culpaError{cause: Unsupported{}}) }
49

Source Files