Skip to content

Commit e539837

Browse files
committed
add first implementation of a function generating a crash-report
1 parent d71d3ec commit e539837

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

main.go

+21
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ func main() {
111111
os.Exit(0)
112112
}
113113

114+
// function used to save panic to a file (WIP)
115+
defer panicToFile()
116+
114117
// Launch main loop in a goroutine
115118
go loop()
116119

@@ -148,6 +151,24 @@ func main() {
148151
Systray.Start()
149152
}
150153

154+
func panicToFile() {
155+
if r := recover(); r != nil {
156+
fileName := "crashreport_" + time.Now().Format("20060102150405") + ".txt"
157+
currDir, err := osext.ExecutableFolder()
158+
if err != nil {
159+
panic(err)
160+
}
161+
162+
crashreport := []byte("stacktrace from panic: \n" + string(debug.Stack()))
163+
164+
err = ioutil.WriteFile(filepath.Join(currDir, fileName), crashreport, 0644)
165+
if err != nil {
166+
panic(err)
167+
}
168+
panic(r)
169+
}
170+
}
171+
151172
func copyExe(from, to string) error {
152173
data, err := ioutil.ReadFile(from)
153174
if err != nil {

0 commit comments

Comments
 (0)