Replies: 8 comments 2 replies
-
|
You can create a function Init to set the default output log as: After that, just use |
Beta Was this translation helpful? Give feedback.
-
|
Open a ticket for a crash reporter. It'll be a function option that receives an error. We can then write a top level recover method that will call this option if available |
Beta Was this translation helpful? Give feedback.
-
|
@leaanthony does this work in v3? |
Beta Was this translation helpful? Give feedback.
-
|
I did do this the following way now I created a package crashdialog // crashdialog_darwin.go
//go:build darwin
// +build darwin
package crashdialog
import (
"fmt"
"os/exec"
)
// ShowCrashDialog displays a native dialog on macOS with the crash report inside a text input for easy copying.
func ShowCrashDialog(crashReport string) error {
appleScript := fmt.Sprintf(`
tell application "System Events"
display dialog "The app has crashed. Please copy the crash report below and send it to support@webridge.nl:" default answer "%s" buttons {"OK"} default button "OK" with icon caution
end tell`, crashReport)
cmd := exec.Command("osascript", "-e", appleScript)
return cmd.Run()
}windows // crashdialog_windows.go
//go:build windows
// +build windows
package crashdialog
import (
"fmt"
"log"
"syscall"
"unsafe"
)
var (
user32 = syscall.NewLazyDLL("user32.dll")
procMessageBoxW = user32.NewProc("MessageBoxW")
)
const (
MB_ICONERROR = 0x00000010
MB_OK = 0x00000000
)
// ShowCrashDialog displays a simple native MessageBox with the crash report.
func ShowCrashDialog(crashReport string) error {
message := fmt.Sprintf("The app has crashed. Please copy the crash report below and send it to support@webridge.nl:\n\n%s", crashReport)
title := "App Crash"
// Windows native MessageBox (without text input but keeps it very simple)
t, _ := syscall.UTF16PtrFromString(title)
c, _ := syscall.UTF16PtrFromString(message)
// Call MessageBoxW from user32.dll
ret, _, _ := procMessageBoxW.Call(0, uintptr(unsafe.Pointer(c)), uintptr(unsafe.Pointer(t)), MB_ICONERROR|MB_OK)
if ret == 0 {
log.Printf("Failed to show dialog")
return fmt.Errorf("failed to show dialog")
}
return nil
}func panicHandler(output string) {
if err := crashdialog.ShowCrashDialog(output); err != nil {
log.Error().Err(err).Msg("Failed to show crashdialog dialog")
}
}
func main() {
exitStatus, err := panicwrap.BasicWrap(panicHandler)
if err != nil {
// Something went wrong setting up the panic wrapper. Unlikely,
// but possible.
panic(err)
}
// If exitStatus >= 0, then we're the parent process and the panicwrap
// re-executed ourselves and completed. Just exit with the proper status.
if exitStatus >= 0 {
os.Exit(exitStatus)
}
app := NewApp() |
Beta Was this translation helpful? Give feedback.
-
|
Hmmm. This still does silently crash without the alert. I don't know why it does.. |
Beta Was this translation helpful? Give feedback.
-
|
windows, set |
Beta Was this translation helpful? Give feedback.
-
|
Maybe Sentry(sentry.io) could be an option. |
Beta Was this translation helpful? Give feedback.
-
|
Great solutions shared here — thanks everyone for contributing workarounds! To summarize what works today: For file-based logging before a crash, the For panic/crash detection with a user-facing dialog, @RichardLindhout's v3 note: A first-class crash reporter option (a function hook that fires on unhandled panics) has been requested — please 👍 the feature request if you want it prioritized. In the meantime the If the silent crash issue persists after putting |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How do I write a report to, says text (.txt) file, if my complied app (.exe) crash?
In other words, simply write all logs to a file, when app crashed.
Thanks,
Beta Was this translation helpful? Give feedback.
All reactions