Skip to content

Commit

Permalink
fix: play panic recover (#238)
Browse files Browse the repository at this point in the history
* chore: ignore node_modules in go

* chore: ignore node_modules in go

* fix: don't panic in pimo play

* fix: lint

* docs: fix changelog

* Update internal/app/pimo/play.go

Co-authored-by: Youen Péron <[email protected]>

---------

Co-authored-by: Youen Péron <[email protected]>
  • Loading branch information
adrienaury and Youen Péron authored Jun 15, 2023
1 parent 9b88a15 commit 8daf79d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +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
- `Fixed` PIMO Play handle panics and recover gracefully when panics occure

## [1.18.0]

Expand Down
18 changes: 18 additions & 0 deletions internal/app/pimo/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ func Play(enableSecurity bool) *echo.Echo {

// play binds client interface data entry to be processed and returns the transformed json to client
func play(ctx echo.Context) error {
// dont't panic
defer func() error {
if r := recover(); r != nil {
log.Error().AnErr("panic", r.(error)).Msg("Recovering from panic in play.")
return ctx.String(http.StatusInternalServerError, r.(error).Error())
}
return nil
}() //nolint:errcheck

config := Config{
EmptyInput: false,
RepeatUntil: "",
Expand Down Expand Up @@ -110,6 +119,15 @@ func play(ctx echo.Context) error {
}

func flowchart(ctx echo.Context) error {
// dont't panic
defer func() error {
if r := recover(); r != nil {
log.Error().AnErr("panic", r.(error)).Msg("Recovering from panic in flow.")
return ctx.String(http.StatusInternalServerError, r.(error).Error())
}
return nil
}() //nolint:errcheck

var dataInput map[string]interface{}

err := ctx.Bind(&dataInput)
Expand Down
5 changes: 3 additions & 2 deletions web/play/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# dependencies
/node_modules
!/node_modules/go.mod
/.pnp
.pnp.js

Expand All @@ -23,6 +24,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Elm
# Elm
elm-stuff/
gen/
gen/
Empty file added web/play/node_modules/go.mod
Empty file.

0 comments on commit 8daf79d

Please sign in to comment.