Skip to content

Commit

Permalink
feat: wrap panics errors in specific PanicError type
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Jul 24, 2024
1 parent b5a8728 commit f3edfbc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion engine/promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ func ensurePromise(p **Promise) {
}

func panicError(r interface{}) error {
return fmt.Errorf("panic: %v", r)
switch r := r.(type) {
case error:
return PanicError{r}
default:
return PanicError{fmt.Errorf("%v", r)}
}
}

type promiseStack []*Promise
Expand Down Expand Up @@ -164,3 +169,12 @@ func (s *promiseStack) recover(err error) error {
// went through all the ancestor promises and still got the unhandled error.
return err
}

// PanicError is an error thrown once panic occurs during the execution of a promise.
type PanicError struct {
OriginErr error
}

func (p PanicError) Error() string {
return fmt.Sprintf("panic: %v", p.OriginErr)
}

0 comments on commit f3edfbc

Please sign in to comment.