/
errors.go
49 lines (39 loc) · 1022 Bytes
/
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
package publiccode
import (
"fmt"
"strings"
)
// A generic parse error.
type ParseError struct {
Reason string
}
func (e ParseError) Error() string {
return e.Reason
}
// ErrorInvalidKey represents an error caused by an invalid key.
type ErrorInvalidKey struct {
Key string
}
func (e ErrorInvalidKey) Error() string {
return fmt.Sprintf("invalid key: %s", e.Key)
}
// ErrorInvalidValue represents an error caused by an invalid value.
type ErrorInvalidValue struct {
Key string
Reason string
}
func (e ErrorInvalidValue) Error() string {
return fmt.Sprintf("%s: %s", e.Key, e.Reason)
}
func newErrorInvalidValue(key string, reason string, args ...interface{}) ErrorInvalidValue {
return ErrorInvalidValue{Key: key, Reason: fmt.Sprintf(reason, args...)}
}
// ErrorParseMulti represents an error caused by a multivalue key.
type ErrorParseMulti []error
func (es ErrorParseMulti) Error() string {
var ss []string
for _, e := range es {
ss = append(ss, e.Error())
}
return strings.Join(ss, "\n")
}