From f38c6c6d1cfe45192fa76ee85f971619a0e3f599 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sun, 11 Dec 2022 20:05:00 +1100 Subject: [PATCH] Add Fatal() --- exp/pkg/application/errors.go | 16 ++++++++++++++++ exp/pkg/application/mainthread.go | 6 ++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 exp/pkg/application/errors.go diff --git a/exp/pkg/application/errors.go b/exp/pkg/application/errors.go new file mode 100644 index 000000000..747142328 --- /dev/null +++ b/exp/pkg/application/errors.go @@ -0,0 +1,16 @@ +package application + +import ( + "fmt" + "os" +) + +func Fatal(message string, args ...interface{}) { + println("*********************** FATAL ***********************") + println("There has been a catastrophic failure in your application.") + println("Please report this error at https://github.com/wailsapp/wails/issues") + println("******************** Error Details ******************") + println(fmt.Sprintf(message, args...)) + println("*********************** FATAL ***********************") + os.Exit(1) +} diff --git a/exp/pkg/application/mainthread.go b/exp/pkg/application/mainthread.go index c91fec8b0..16068c39b 100644 --- a/exp/pkg/application/mainthread.go +++ b/exp/pkg/application/mainthread.go @@ -7,7 +7,6 @@ extern void dispatch(unsigned int id); */ import "C" import ( - "os" "sync" ) @@ -22,7 +21,7 @@ func generateFunctionStoreID() uint { } startID++ if startID == 0 { - panic("Too many functions stored") + Fatal("Too many functions have been dispatched to the main thread") } } } @@ -41,8 +40,7 @@ func dispatchCallback(callbackID C.uint) { id := uint(callbackID) fn := mainThreadFuntionStore[id] if fn == nil { - println("***** dispatchCallback called with invalid id: ", id) - os.Exit(1) + Fatal("dispatchCallback called with invalid id: ", id) } delete(mainThreadFuntionStore, id) mainThreadFuntionStoreLock.RUnlock()