Skip to content

Commit

Permalink
Return a higher-level error when state is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Oct 18, 2023
1 parent 0362e4e commit fddb6ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions coroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func LoadContext[R, S any]() *Context[R, S] {
}
}

// ErrNotDurable is an error that occurs when attempting to
// serialize a coroutine that is not durable.
var ErrNotDurable = errors.New("only durable coroutines can be serialized")
var (
// ErrNotDurable is an error that occurs when attempting to
// serialize a coroutine that is not durable.
ErrNotDurable = errors.New("only durable coroutines can be serialized")

// ErrInvalidState is an error that occurs when attempting to
// deserialize a coroutine that was serialized in another build.
ErrInvalidState = errors.New("durable coroutine was serialized in another build")
)
4 changes: 4 additions & 0 deletions coroutine_durable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package coroutine

import (
"errors"
"runtime"
"unsafe"

Expand Down Expand Up @@ -95,6 +96,9 @@ func (c *Context[R, S]) Unmarshal(b []byte) (int, error) {
start := len(b)
v, b, err := types.Deserialize(b)
if err != nil {
if errors.Is(err, types.ErrBuildIDMismatch) {
return 0, ErrInvalidState
}
return 0, err
}
s := v.(*serializedCoroutine)
Expand Down

0 comments on commit fddb6ae

Please sign in to comment.