From 0dce279a896c604054f835ac921faa20af26b610 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 25 Jul 2019 15:12:04 +0200 Subject: ui: improve error handling Signed-off-by: Alexander Neumann Signed-off-by: Jason A. Donenfeld --- ui/ui.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'ui/ui.go') diff --git a/ui/ui.go b/ui/ui.go index aa0c7528..c98edf18 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -26,7 +26,7 @@ func RunUI() { runtime.LockOSThread() defer func() { if err := recover(); err != nil { - walk.MsgBox(nil, "Panic", fmt.Sprint(err, "\n\n", string(debug.Stack())), walk.MsgBoxIconError) + showErrorCustom(nil, "Panic", fmt.Sprint(err, "\n\n", string(debug.Stack()))) panic(err) } }() @@ -95,7 +95,7 @@ func RunUI() { if shouldQuitManagerWhenExiting { _, err := manager.IPCClientQuit(true) if err != nil { - walk.MsgBox(nil, "Error Exiting WireGuard", fmt.Sprintf("Unable to exit service due to: %v. You may want to stop WireGuard from the service manager.", err), walk.MsgBoxIconError) + showErrorCustom(nil, "Error Exiting WireGuard", fmt.Sprintf("Unable to exit service due to: %v. You may want to stop WireGuard from the service manager.", err)) } } } @@ -104,3 +104,21 @@ func onQuit() { shouldQuitManagerWhenExiting = true walk.App().Exit(0) } + +func showError(err error, owner walk.Form) bool { + if err == nil { + return false + } + + showErrorCustom(owner, "Error", err.Error()) + + return true +} + +func showErrorCustom(owner walk.Form, title, message string) { + walk.MsgBox(owner, title, message, walk.MsgBoxIconError) +} + +func showWarningCustom(owner walk.Form, title, message string) { + walk.MsgBox(owner, title, message, walk.MsgBoxIconWarning) +} -- cgit v1.2.3-59-g8ed1b