Skip to content

style(engine): expose atom for panic_error term #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions engine/promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var (
falsePromise = &Promise{ok: false}
)

var (
AtomPanicError = NewAtom("panic_error")
)

// PromiseFunc defines the type of a function that returns a promise.
type PromiseFunc = func(context.Context) *Promise

Expand Down Expand Up @@ -165,9 +169,9 @@ func panicError(r interface{}) error {
case Exception:
return r
case error:
return Exception{term: atomError.Apply(NewAtom("panic_error").Apply(NewAtom(r.Error())))}
return Exception{term: atomError.Apply(AtomPanicError.Apply(NewAtom(r.Error())))}
default:
return Exception{term: atomError.Apply(NewAtom("panic_error").Apply(NewAtom(fmt.Sprintf("%v", r))))}
return Exception{term: atomError.Apply(AtomPanicError.Apply(NewAtom(fmt.Sprintf("%v", r))))}
}
}

Expand Down Expand Up @@ -217,12 +221,3 @@ 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)
}