-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollecting-panic-and-error.yak
More file actions
113 lines (90 loc) · 2.94 KB
/
collecting-panic-and-error.yak
File metadata and controls
113 lines (90 loc) · 2.94 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// fetch local panic info
yakitHome = yakit.GetHomeDir()
log.Info("HOME: %v", yakitHome)
infos, err = file.ReadDirInfoInDirectory(yakitHome)
die(err)
zipMaterial = {}
handle = filePath => {
f = file.Open(filePath)~
defer f.Close()
lastBuf = []
for {
try {
i = f.ReadLine()~
prefix = ""
havePanic = i.Contains(`Current goroutine call stack:`)
haveASTErr = false // i.Contains("parse AST FrontEnd error:")
haveError = havePanic || haveASTErr
if havePanic {
prefix = "panic"
}
lastBuf.Push(i)
if lastBuf.Len() >= 200 {
lastBuf.Shift()
}
if haveASTErr {
prefix = "ast-error"
}
if haveError {
buf = bufio.NewBuffer()
for in 200 {
line, err = f.ReadLine()
if err != nil {
break
}
buf.WriteString(line)
buf.WriteByte('\n')
}
results = buf.String()
a = codec.Sha256((results))
if prefix == "panic" {
hashed = bufio.NewBuffer()
for ret in re.FindAll(
results[:2048],
`yaklang/(.*)\.go\:\d+`,
) {
hashed.WriteString(ret)
hashed.Write("\n")
}
println(string(hashed))
a = codec.Sha256(hashed.String())
}
lastBufBytes = str.Join(lastBuf, "\n")
lastBuf = []
fileName = "sample/%v-%v.txt" % [prefix, a]
if fileName in zipMaterial {
println("%v is existed" % fileName)
continue
}
println("sample: %v" % fileName)
zipMaterial[fileName] = lastBufBytes + "\n" + results
}
} catch e {
break
}
}
}
for i in infos {
if !i.IsDir {
continue
}
dir, name = file.Split(i.Path)
name = name.Trim("/", "\\")
if name == "engine-log" || name == "temp" {
file.Walk(
i.Path,
logFile => {
if !logFile.Path.HasSuffix(".txt") {return true}
println(logFile.Path)
handle(logFile.Path)
return true
},
)
}
}
log.Info("fetch zip material: %v", len(zipMaterial))
bytes, err = zip.CompressRaw(zipMaterial)
die(err)
ts = timestampToDatetime(timestamp()).ReplaceAll(" ", "-").ReplaceAll(":", "-")
targetFile = file.Join(yakitHome, "temp", f"yaklang-panic-log-${ts}.zip")
file.Save(targetFile, bytes)