Skip to content

Commit

Permalink
refactor(statemachine): improve error message for invalid state trans…
Browse files Browse the repository at this point in the history
…itions

- Updated error message in `Transition` method to include the current
  and target states, enhancing debugging and clarity.
- Replaced generic `errors.New` with `fmt.Errorf` for more descriptive
  error messages.
  • Loading branch information
eliseomartelli committed Feb 18, 2025
1 parent 8d57afa commit 907fda9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions statemachine.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package micromachine

import (
"errors"
"fmt"
"sync"
)

Expand Down Expand Up @@ -61,7 +61,11 @@ func (sm *Micromachine[T]) Transition(to T) error {
sm.state = to
return nil
}
return errors.New("invalid state transition")
return fmt.Errorf(
"invalid state transition from '%v' to '%v'",
sm.state,
to,
)
}

// State returns the current state of the state machine.
Expand Down

0 comments on commit 907fda9

Please sign in to comment.