Skip to content

Commit

Permalink
Merge pull request #23 from axone-protocol/style/minor-improvements
Browse files Browse the repository at this point in the history
style(engine): expose atom for panic_error term
  • Loading branch information
ccamel authored Nov 26, 2024
2 parents b16f8f9 + 84f0213 commit d900321
Showing 1 changed file with 6 additions and 11 deletions.
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)
}

0 comments on commit d900321

Please sign in to comment.