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

45 lines
1.4 KiB
Go

package game
import (
"errors"
"fmt"
)
// ErrNotFound reports that a game record was requested but does not exist
// in the store.
var ErrNotFound = errors.New("game not found")
// ErrConflict reports that a game mutation could not be applied because the
// record changed concurrently or failed a compare-and-swap guard.
var ErrConflict = errors.New("game conflict")
// ErrInvalidTransition is the sentinel returned when Transition rejects a
// `(from, to, trigger)` triplet.
var ErrInvalidTransition = errors.New("invalid game status transition")
// InvalidTransitionError stores the rejected `(from, to, trigger)` triplet
// 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
// Trigger stores the transition trigger that was attempted.
Trigger Trigger
}
// Error reports a human-readable summary of the rejected triplet.
func (err *InvalidTransitionError) Error() string {
return fmt.Sprintf(
"invalid game status transition from %q to %q with trigger %q",
err.From, err.To, err.Trigger,
)
}
// Unwrap returns ErrInvalidTransition so errors.Is recognizes the sentinel.
func (err *InvalidTransitionError) Unwrap() error {
return ErrInvalidTransition
}