Files
galaxy-game/lobby/internal/domain/application/errors.go
T
2026-04-25 23:20:55 +02:00

43 lines
1.3 KiB
Go

package application
import (
"errors"
"fmt"
)
// ErrNotFound reports that an application record was requested but does
// not exist in the store.
var ErrNotFound = errors.New("application not found")
// ErrConflict reports that an application mutation could not be applied.
// It is returned for single-active-application violations and for
// compare-and-swap mismatches on status transitions.
var ErrConflict = errors.New("application conflict")
// ErrInvalidTransition is the sentinel returned when Transition rejects a
// `(from, to)` pair.
var ErrInvalidTransition = errors.New("invalid application status transition")
// InvalidTransitionError stores the rejected `(from, to)` pair and wraps
// ErrInvalidTransition so callers can match it with errors.Is.
type InvalidTransitionError struct {
// From stores the source status that was attempted to leave.
From Status
// To stores the destination status that was attempted to enter.
To Status
}
// Error reports a human-readable summary of the rejected pair.
func (err *InvalidTransitionError) Error() string {
return fmt.Sprintf(
"invalid application status transition from %q to %q",
err.From, err.To,
)
}
// Unwrap returns ErrInvalidTransition so errors.Is recognizes the sentinel.
func (err *InvalidTransitionError) Unwrap() error {
return ErrInvalidTransition
}