-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherr.go
65 lines (52 loc) · 995 Bytes
/
err.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
64
65
package main
type myError struct {
code myErrorCode
info string
}
func (e *myError) Error() (output string) {
switch e.code {
case code_OK:
output = " ok"
case code_SKIPPED:
output = " skipped"
case code_NEW_SUM:
output = " new checksum"
case code_BAD_SUM:
output = " BAD CHECKSUM"
case code_NOT_FOUND:
output = "file not found"
case code_NEWER:
output = " file newer"
case code_OTHER:
output = " error"
}
if e.info != "" {
output += ": "
output += e.info
}
return
}
func NewError(code myErrorCode, f *fileJob, info string) (err *myError) {
if f != nil {
err = &myError{code, f.Fpath + " " + info}
} else {
err = &myError{code, info}
}
return err
}
func WrapError(err error) (myerr *myError) {
if err == nil {
return nil
}
return &myError{code_OTHER, err.Error()}
}
type myErrorCode int
const (
code_OK myErrorCode = iota
code_SKIPPED
code_NEW_SUM
code_BAD_SUM
code_NOT_FOUND
code_NEWER
code_OTHER
)