-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract-panic-and-ast-error-from-log.yak
61 lines (50 loc) · 1.58 KB
/
extract-panic-and-ast-error-from-log.yak
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
f = file.Open("/tmp/a.txt")~
defer f.Close()
for {
try {
i = f.ReadLine()~
prefix = ""
havePanic = i.Contains(`Current goroutine call stack:`)
haveASTErr = i.Contains("parse AST FrontEnd error:")
haveError = havePanic || haveASTErr
if havePanic {
prefix = "panic"
}
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.Write("\n")
}
results = buf.String()
a = codec.Sha256((results))
if prefix == "panic" {
hashed = bufio.NewBuffer()
for ret in re.FindAll(
results[:2048],
`/Users/v1ll4n/Projects/yaklang/(.*)\.go\:\d+`,
) {
hashed.WriteString(ret)
hashed.Write("\n")
}
a = codec.Sha256(hashed.String())
}
fileName = "/Users/v1ll4n/Projects/sample/%v-%v.txt" % [prefix, a]
if file.IsExisted(fileName) {
println("%v is existed" % fileName)
continue
}
println("sample: %v" % fileName)
file.Save(fileName, results)
}
} catch e {
break
}
}