File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,9 @@ func main() {
111
111
os .Exit (0 )
112
112
}
113
113
114
+ // function used to save panic to a file (WIP)
115
+ defer panicToFile ()
116
+
114
117
// Launch main loop in a goroutine
115
118
go loop ()
116
119
@@ -148,6 +151,24 @@ func main() {
148
151
Systray .Start ()
149
152
}
150
153
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
+
151
172
func copyExe (from , to string ) error {
152
173
data , err := ioutil .ReadFile (from )
153
174
if err != nil {
You can’t perform that action at this time.
0 commit comments