From 4598af4d7a48eb7ec98e1227a4c36949eaf2cbd3 Mon Sep 17 00:00:00 2001 From: ronaldinho_x86 Date: Fri, 17 Jan 2025 13:45:54 +0800 Subject: [PATCH] recover from process message instead crash the whole app (#4016) * recover from process message instead crash the whole app * update changelog.mdx (#4015) --- v2/internal/frontend/dispatcher/dispatcher.go | 16 +++++++++++++++- website/src/pages/changelog.mdx | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/v2/internal/frontend/dispatcher/dispatcher.go b/v2/internal/frontend/dispatcher/dispatcher.go index 97d9b32e9..60a99f467 100644 --- a/v2/internal/frontend/dispatcher/dispatcher.go +++ b/v2/internal/frontend/dispatcher/dispatcher.go @@ -2,6 +2,7 @@ package dispatcher import ( "context" + "fmt" "github.com/pkg/errors" "github.com/wailsapp/wails/v2/internal/binding" "github.com/wailsapp/wails/v2/internal/frontend" @@ -29,7 +30,20 @@ func NewDispatcher(ctx context.Context, log *logger.Logger, bindings *binding.Bi } } -func (d *Dispatcher) ProcessMessage(message string, sender frontend.Frontend) (string, error) { +func (d *Dispatcher) ProcessMessage(message string, sender frontend.Frontend) (_ string, err error) { + defer func() { + if e := recover(); e != nil { + if errPanic, ok := e.(error); ok { + err = errPanic + } else { + err = fmt.Errorf("%v", e) + } + } + if err != nil { + d.log.Error("process message error: %s -> %s", message, err) + } + }() + if message == "" { return "", errors.New("No message to process") } diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 9ba4eb43d..ee9f029f3 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [windows] Fixed frameless window flickering when minimizing/restoring by preventing unnecessary redraws [#3951](https://github.com/wailsapp/wails/issues/3951) - Fixed failed models.ts build due to non-json-encodable Go types [PR](https://github.com/wailsapp/wails/pull/3975) by [@pbnjay](https://github.com/pbnjay) - Fixed more binding and typescript export bugs [PR](https://github.com/wailsapp/wails/pull/3978) by [@pbnjay](https://github.com/pbnjay) +- Fixed Dispatcher.ProcessMessage crash process instead of return error [PR](https://github.com/wailsapp/wails/pull/4016) [#4015](https://github.com/wailsapp/wails/issues/4015) by [@ronaldinho_x86](https://github.com/RonaldinhoL) ### Changed - Allow to specify macos-min-version externally. Implemented by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/3756)