summaryrefslogtreecommitdiff
path: root/internal/fsm
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-06-20 15:20:18 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-06-20 15:20:18 +0200
commit2252135fadb8c579ad27345e3203be755130e3cd (patch)
treeed5a530e85b43736fc0bc28c927cfa8488f9199b /internal/fsm
parent7af07c596166bf93b79a9d0816b1950dde360fb9 (diff)
Refactor: Errors to have one custom type that is to be wrapped
- For this an `internal/types` package is created with a custom error type - This custom error type can give back the cause and traceback of an error
Diffstat (limited to 'internal/fsm')
-rw-r--r--internal/fsm/fsm.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go
index bb7f330..3d0bfd6 100644
--- a/internal/fsm/fsm.go
+++ b/internal/fsm/fsm.go
@@ -1,12 +1,15 @@
package fsm
import (
+ "errors"
"fmt"
"os"
"os/exec"
"path"
"sort"
+
"github.com/jwijenbergh/eduvpn-common/internal/log"
+ "github.com/jwijenbergh/eduvpn-common/internal/types"
)
type (
@@ -209,20 +212,26 @@ func (fsm *FSM) GenerateGraph() string {
return fsm.generateMermaidGraph()
}
-type FSMWrongStateTransitionError struct {
+type DeregisteredError struct{}
+
+func (e DeregisteredError) CustomError() *types.WrappedErrorMessage {
+ return &types.WrappedErrorMessage{Message: "Client not registered with the GO library", Err: errors.New("the current FSM state is deregistered, but the function needs a state that is not deregistered")}
+}
+
+type WrongStateTransitionError struct {
Got FSMStateID
Want FSMStateID
}
-func (e *FSMWrongStateTransitionError) Error() string {
- return fmt.Sprintf("wrong FSM state, got: %s, want a state with a transition to: %s", e.Got.String(), e.Want.String())
+func (e WrongStateTransitionError) CustomError() *types.WrappedErrorMessage {
+ return &types.WrappedErrorMessage{Message: "Wrong FSM transition", Err: errors.New(fmt.Sprintf("wrong FSM state, got: %s, want: a state with a transition to: %s", e.Got.String(), e.Want.String()))}
}
-type FSMWrongStateError struct {
+type WrongStateError struct {
Got FSMStateID
Want FSMStateID
}
-func (e *FSMWrongStateError) Error() string {
- return fmt.Sprintf("wrong FSM state, got: %s, want: %s", e.Got.String(), e.Want.String())
+func (e WrongStateError) CustomError() *types.WrappedErrorMessage {
+ return &types.WrappedErrorMessage{Message: "Wrong FSM State", Err: errors.New(fmt.Sprintf("wrong FSM state, got: %s, want: %s", e.Got.String(), e.Want.String()))}
}