Skip to content

Commit 8daf79d

Browse files
adrienauryYouen Péron
andauthored
fix: play panic recover (#238)
* 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]>
1 parent 9b88a15 commit 8daf79d

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Types of changes
1717
## [1.18.1]
1818

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

2222
## [1.18.0]
2323

internal/app/pimo/play.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ func Play(enableSecurity bool) *echo.Echo {
4646

4747
// play binds client interface data entry to be processed and returns the transformed json to client
4848
func play(ctx echo.Context) error {
49+
// dont't panic
50+
defer func() error {
51+
if r := recover(); r != nil {
52+
log.Error().AnErr("panic", r.(error)).Msg("Recovering from panic in play.")
53+
return ctx.String(http.StatusInternalServerError, r.(error).Error())
54+
}
55+
return nil
56+
}() //nolint:errcheck
57+
4958
config := Config{
5059
EmptyInput: false,
5160
RepeatUntil: "",
@@ -110,6 +119,15 @@ func play(ctx echo.Context) error {
110119
}
111120

112121
func flowchart(ctx echo.Context) error {
122+
// dont't panic
123+
defer func() error {
124+
if r := recover(); r != nil {
125+
log.Error().AnErr("panic", r.(error)).Msg("Recovering from panic in flow.")
126+
return ctx.String(http.StatusInternalServerError, r.(error).Error())
127+
}
128+
return nil
129+
}() //nolint:errcheck
130+
113131
var dataInput map[string]interface{}
114132

115133
err := ctx.Bind(&dataInput)

web/play/.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# dependencies
44
/node_modules
5+
!/node_modules/go.mod
56
/.pnp
67
.pnp.js
78

@@ -23,6 +24,6 @@ npm-debug.log*
2324
yarn-debug.log*
2425
yarn-error.log*
2526

26-
# Elm
27+
# Elm
2728
elm-stuff/
28-
gen/
29+
gen/

web/play/node_modules/go.mod

Whitespace-only changes.

0 commit comments

Comments
 (0)