From f3edfbc2b606a6b5639cf317edbf17859b2d8e07 Mon Sep 17 00:00:00 2001 From: Benjamin DENEUX Date: Wed, 24 Jul 2024 10:58:39 +0200 Subject: [PATCH] feat: wrap panics errors in specific PanicError type --- engine/promise.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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) +}