MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / handlePanic

Method handlePanic

internal/nodes/node_panic.go:17–44  ·  view source on GitHub ↗

处理异常

()

Source from the content-addressed store, hash-verified

15
16// 处理异常
17func (this *Node) handlePanic() {
18 // 如果是在前台运行就直接返回
19 backgroundEnv, _ := os.LookupEnv("EdgeBackground")
20 if backgroundEnv != "on" {
21 return
22 }
23
24 var panicFile = Tea.Root + "/logs/panic.log"
25
26 // 分析panic
27 data, err := os.ReadFile(panicFile)
28 if err == nil {
29 var index = bytes.Index(data, []byte("panic:"))
30 if index >= 0 {
31 remotelogs.Error("NODE", "系统错误,请上报给开发者: "+string(data[index:]))
32 }
33 }
34
35 fp, err := os.OpenFile(panicFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0777)
36 if err != nil {
37 logs.Println("NODE", "open 'panic.log' failed: "+err.Error())
38 return
39 }
40 err = syscall.Dup2(int(fp.Fd()), int(os.Stderr.Fd()))
41 if err != nil {
42 logs.Println("NODE", "write to 'panic.log' failed: "+err.Error())
43 }
44}
45

Callers 1

StartMethod · 0.95

Calls 3

ErrorFunction · 0.92
FdMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected