Skip to content

Commit a03fc20

Browse files
committed
Output stackstrace in log in case of crash
1 parent 12a1bf6 commit a03fc20

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/exec"
1010
"path/filepath"
11+
"runtime/debug"
1112

1213
"github.com/bcmi-labs/arduino-language-server/handler"
1314
"github.com/bcmi-labs/arduino-language-server/streams"
@@ -33,7 +34,13 @@ func main() {
3334

3435
if enableLogging {
3536
logfile := openLogFile("inols-err.log")
36-
defer logfile.Close()
37+
defer func() {
38+
// In case of panic output the stack trace in the log file before exiting
39+
if r := recover(); r != nil {
40+
log.Println(string(debug.Stack()))
41+
}
42+
logfile.Close()
43+
}()
3744
log.SetOutput(logfile)
3845
} else {
3946
log.SetOutput(os.Stderr)

0 commit comments

Comments
 (0)