Skip to content

Commit

Permalink
fix: handle panics and recover gracefully when panics occure (#237)
Browse files Browse the repository at this point in the history
* fix: handle panics and recover gracefully when panics occure

* docs: Update CHANGELOG.md

---------

Co-authored-by: Adrien Aury <[email protected]>
  • Loading branch information
Youen Péron and adrienaury authored Jun 14, 2023
1 parent 5fb95bf commit 9b88a15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Types of changes
## [1.18.1]

- `Fixed` local seed parameter should be consistent between different jsonpath
- `Fixed` PIMO Play web assembly version handle panics and recover gracefully when panics occure

## [1.18.0]

Expand Down
18 changes: 18 additions & 0 deletions wasm/pimo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func main() {
reject := args[1]

go func() {
// dont't panic
defer func() {
if r := recover(); r != nil {
log.Error().AnErr("panic", r.(error)).Msg("Recovering from panic in play.")
errorObject := errorConstructor.New(r.(error).Error())
reject.Invoke(errorObject)
}
}()

data, err := play(yaml, data)
if err != nil {
// err should be an instance of `error`, eg `errors.New("some error")`
Expand All @@ -100,6 +109,15 @@ func main() {
reject := args[1]

go func() {
// dont't panic
defer func() {
if r := recover(); r != nil {
log.Error().AnErr("panic", r.(error)).Msg("Recovering from panic in flow")
errorObject := errorConstructor.New(r.(error).Error())
reject.Invoke(errorObject)
}
}()

pdef, err := model.LoadPipelineDefinitionFromYAML([]byte(yaml))
if err != nil {
log.Err(err).Msg("Cannot load pipeline definition")
Expand Down

0 comments on commit 9b88a15

Please sign in to comment.