List valid actions in invalid_state errors#228
Conversation
Every caller-facing ErrInvalidState now names the current state and the user-facing API actions that are valid from it, e.g.: cannot restore from state Paused (no actions valid from this state) cannot start from state Running, valid actions from Running: stop, standby, snapshot, fork (with from_running=true), update Adds State.UserActions and NewInvalidStateError helpers in state.go and routes start/stop/standby/restore/fork/snapshot/restore_snapshot/update and the scheduled-snapshot path through them.
✱ Stainless preview builds for hypemanThis PR will update the Edit this comment to update it. It will appear in the SDK's changelogs. ✅ hypeman-typescript studio · code · diff
✅ hypeman-go studio · code · diff
✅ hypeman-openapi studio · code · diff
This comment is auto-generated by GitHub Actions and is automatically kept up to date as you push. |
Summary
Caller hit `invalid state transition: cannot restore from state Paused` and had no way to know what they were allowed to do instead. Now every caller-facing `ErrInvalidState` message names the current state and the user-facing API actions valid from it.
Before:
```
invalid state transition: cannot restore from state Paused
invalid state transition: cannot start from state Running, must be Stopped
invalid state transition: stopped snapshot requires source in Stopped, got Running
```
After:
```
invalid state transition: cannot restore from state Paused (no actions valid from this state)
invalid state transition: cannot start from state Running, valid actions from Running: stop, standby, snapshot, fork (with from_running=true), update
invalid state transition: cannot snapshot from state Running, valid actions from Running: stop, standby, snapshot, fork (with from_running=true), update
```
Approach
Test plan