-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanic.go
37 lines (32 loc) · 1.11 KB
/
panic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"runtime/debug"
"time"
)
/* Handles panics */
const panicDumpName = "panic.dat"
const pnaicLogName = "panic.log"
func reportPanic(desc *descData, format string, args ...interface{}) {
if r := recover(); r != nil {
now := time.Now().UTC().UnixNano()
panicFile := fmt.Sprintf("%v/%v/%v-%v", DATA_DIR, PANIC_DIR, now, panicDumpName)
f, err := os.Create(panicFile)
if err == nil {
debug.WriteHeapDump(f.Fd())
f.Close()
} else {
critLog("Failed to write '%v' file.", panicDumpName)
}
_, filename, line, _ := runtime.Caller(4)
input := fmt.Sprintf(format, args...)
desc.sendln("Sorry, something went wrong running the %v.", input)
buf := fmt.Sprintf("(GAME PANIC)"+NEWLINE+"BUILD:%v-%v-%v"+NEWLINE+"Label:%v File: %v Line: %v"+NEWLINE+"Error:%v"+NEWLINE+NEWLINE+"Stack Trace:"+NEWLINE+"%v"+NEWLINE, VERSION, VWHEN, CODENAME, input, filepath.Base(filename), line, r, string(debug.Stack()))
panicLogFile := fmt.Sprintf("%v/%v/%v-%v", DATA_DIR, PANIC_DIR, now, pnaicLogName)
os.WriteFile(panicLogFile, []byte(buf), 0660)
critLog(buf)
}
}