-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
60 lines (51 loc) · 1.02 KB
/
errors.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
package unixodbc
import (
"errors"
"fmt"
)
var (
ErrNotImplemented = errors.New("not implemented")
)
type MultipleErrors map[string]error
func (m MultipleErrors) Error() error {
if len(m) == 0 {
return nil
}
var combinedErrMsg string
for desc, err := range m {
if err != nil {
//TODO(ninthclowd): use errors.join and implement unwrap
if combinedErrMsg == "" {
combinedErrMsg = fmt.Sprintf("%s: %s", desc, err.Error())
} else {
combinedErrMsg = fmt.Sprintf("\n%s: %s", desc, err.Error())
}
}
}
if combinedErrMsg != "" {
return errors.New(combinedErrMsg)
}
return nil
}
type DiagRec struct {
State string
ErrorCode int
Message string
}
var _ error = (*Error)(nil)
type Error struct {
DiagRecords []*DiagRec
}
func (e *Error) Error() string {
message := ""
for i, record := range e.DiagRecords {
if i > 0 {
message += "\n"
}
message += fmt.Sprintf("[%s:%d]", record.State, record.ErrorCode)
if record.Message != "" {
message += " " + record.Message
}
}
return message
}