forked from x-motemen/gore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errfilter.go
63 lines (56 loc) · 1.2 KB
/
errfilter.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
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
package gore
import (
"bytes"
"io"
"golang.org/x/text/transform"
)
func newErrFilter(w io.Writer) io.WriteCloser {
return transform.NewWriter(w, &errTransformer{})
}
type errTransformer struct{}
func (w *errTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
var i int
for {
if atEOF {
if i = len(src) - 1; i < 0 {
break
}
} else {
if i = bytes.IndexByte(src, '\n'); i < 0 {
err = transform.ErrShortSrc
break
}
}
res := replaceErrMsg(src[:i+1])
if nDst+len(res) > len(dst) {
err = transform.ErrShortDst
break
}
src = src[i+1:]
nSrc += i + 1
nDst += copy(dst[nDst:], res)
if len(src) == 0 {
break
}
}
return
}
func (w *errTransformer) Reset() {}
func replaceErrMsg(p []byte) []byte {
if bytes.HasPrefix(p, []byte("# command-line-arguments")) {
return nil
}
if cs := "build command-line-arguments: "; bytes.HasPrefix(p, []byte(cs)) {
return p[len(cs):]
}
if bytes.HasPrefix(p, []byte(`warning: pattern "all" matched no module dependencies`)) {
return nil
}
if i := bytes.Index(p, []byte("gore_session.go")); i >= 0 {
if j := bytes.IndexRune(p[i:], ' '); j >= 0 {
return p[i+j+1:]
}
return p
}
return p
}