named error types

main
Nick Dumas 2 years ago
parent bc70a6ca28
commit cd9d4829a8

@ -2,9 +2,13 @@ package fsm
import (
"context"
"errors"
"fmt"
)
var NoMoreTransitions = errors.New("no more transitions")
var InvalidEvent = errors.New("invalid event")
type State string
type Event string
@ -32,12 +36,12 @@ func (m *StateMachine) getCurrentNode() *Node {
func (m *StateMachine) getNextNode(event Event) (*Node, error) {
if m.CurrentNode == nil {
return nil, fmt.Errorf("nowhere to go anymore!\n")
return nil, NoMoreTransitions
}
transition, ok := m.CurrentNode.Transitions[event]
if !ok {
return nil, fmt.Errorf("invalid event: %v", event)
return nil, InvalidEvent
}
return transition.Node, nil

Loading…
Cancel
Save