-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
42 lines (30 loc) · 741 Bytes
/
Copy patherrors.go
File metadata and controls
42 lines (30 loc) · 741 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
41
42
package ecto
import (
"encoding/json"
"fmt"
)
var errRequired = Error("required")
type Error string
func Errorf(format string, args ...any) Error { return Error(fmt.Sprintf(format, args...)) }
func (e Error) Error() string { return string(e) }
type ListError []Error
func (e ListError) JSON() json.RawMessage {
b, _ := json.Marshal(e)
return b
}
func (e ListError) Error() string { return string(e.JSON()) }
type MapError map[string]error
func (e *MapError) Add(key string, err error) {
if err == nil {
return
}
if *e == nil {
*e = make(map[string]error)
}
(*e)[key] = err
}
func (e MapError) JSON() json.RawMessage {
b, _ := json.Marshal(e)
return b
}
func (e MapError) Error() string { return string(e.JSON()) }