-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror.go
More file actions
40 lines (31 loc) · 722 Bytes
/
error.go
File metadata and controls
40 lines (31 loc) · 722 Bytes
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
package schema
import (
"encoding/json"
"errors"
"fmt"
"strings"
)
// MismatchError is represented as a map of field mismatch errors.
type MismatchError map[string]interface{}
func (err MismatchError) Error() string {
b := strings.Builder{}
for key, val := range err {
if s, ok := val.(string); ok {
b.WriteString(fmt.Sprintf("%s: %s", key, s))
b.WriteString(", ")
}
}
s := b.String()
// Remove the trailing ", "
if s != "" {
s = s[:len(s)-2]
}
return s
}
func (err MismatchError) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}(err))
}
var (
ErrInvalidDst = errors.New("dst must be a pointer to a struct")
ErrNilSrc = errors.New("src must not be nil")
)