From d050b3de259c6ab1ebbee75eff1940dbbc84ced9 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 26 Feb 2025 17:12:02 +0900 Subject: app: define errors in a separate file Signed-off-by: Ophestra --- internal/app/process.go | 72 ------------------------------------------------- 1 file changed, 72 deletions(-) (limited to 'internal/app/process.go') diff --git a/internal/app/process.go b/internal/app/process.go index b0d60311..fe17f0b7 100644 --- a/internal/app/process.go +++ b/internal/app/process.go @@ -211,75 +211,3 @@ func (seal *outcome) Run(ctx context.Context, rs *fst.RunState) error { return earlyStoreErr.equiv("cannot save process state:") } - -// StateStoreError is returned for a failed state save -type StateStoreError struct { - // whether inner function was called - Inner bool - // returned by the Save/Destroy method of [state.Cursor] - InnerErr error - // returned by the Do method of [state.Store] - DoErr error - // stores an arbitrary store operation error - OpErr error - // stores arbitrary errors - Err []error -} - -// save saves arbitrary errors in [StateStoreError] once. -func (e *StateStoreError) save(errs []error) { - if len(errs) == 0 || e.Err != nil { - panic("invalid call to save") - } - e.Err = errs -} - -func (e *StateStoreError) equiv(a ...any) error { - if e.Inner && e.InnerErr == nil && e.DoErr == nil && e.OpErr == nil && errors.Join(e.Err...) == nil { - return nil - } else { - return fmsg.WrapErrorSuffix(e, a...) - } -} - -func (e *StateStoreError) Error() string { - if e.Inner && e.InnerErr != nil { - return e.InnerErr.Error() - } - if e.DoErr != nil { - return e.DoErr.Error() - } - if e.OpErr != nil { - return e.OpErr.Error() - } - if err := errors.Join(e.Err...); err != nil { - return err.Error() - } - - // equiv nullifies e for values where this is reached - panic("unreachable") -} - -func (e *StateStoreError) Unwrap() (errs []error) { - errs = make([]error, 0, 3) - if e.InnerErr != nil { - errs = append(errs, e.InnerErr) - } - if e.DoErr != nil { - errs = append(errs, e.DoErr) - } - if e.OpErr != nil { - errs = append(errs, e.OpErr) - } - if err := errors.Join(e.Err...); err != nil { - errs = append(errs, err) - } - return -} - -// A RevertCompoundError encapsulates errors returned by -// the Revert method of [system.I]. -type RevertCompoundError interface { - Error() string - Unwrap() []error -} -- cgit v1.3.1