diff --git a/engine/promise.go b/engine/promise.go index 0b043c0..f3a94b5 100644 --- a/engine/promise.go +++ b/engine/promise.go @@ -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 @@ -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) +}