forked from mitchellh/mapstructure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
74 lines (62 loc) · 1.54 KB
/
error.go
File metadata and controls
74 lines (62 loc) · 1.54 KB
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
66
67
68
69
70
71
72
73
74
package mapstructure
import (
"fmt"
"reflect"
"sort"
"strings"
)
// Error implements the error interface and can represents multiple
// errors that occur in the course of a single decode.
type Error struct {
Errors []error
}
func (e *Error) Error() string {
points := make([]string, len(e.Errors))
for i, err := range e.Errors {
points[i] = fmt.Sprintf("* %s", err)
}
sort.Strings(points)
return fmt.Sprintf(
"%d error(s) decoding:\n\n%s",
len(e.Errors), strings.Join(points, "\n"))
}
// WrappedErrors implements the errwrap.Wrapper interface to make this
// return value more useful with the errwrap and go-multierror libraries.
func (e *Error) WrappedErrors() []error {
if e == nil {
return nil
}
return e.Errors
}
func (e *Error) append(err error) {
switch inerr := err.(type) {
case *Error:
e.Errors = append(e.Errors, inerr.Errors...)
default:
e.Errors = append(e.Errors, inerr)
}
}
type ParseError struct {
Name string
Val interface{}
To reflect.Kind
Err error
}
func (e *ParseError) Error() string {
return fmt.Sprintf("cannot parse '%s' as %v: %v", e.Name, e.To, e.Err)
}
func parseError(name string, val interface{}, to reflect.Kind, err error) *ParseError {
return &ParseError{name, val, to, err}
}
type OverflowError struct {
Name string
Val interface{}
To reflect.Kind
}
func (e *OverflowError) Error() string {
return fmt.Sprintf("cannot parse '%s', %v overflows %v",
e.Name, e.Val, e.To)
}
func overflowError(name string, val interface{}, to reflect.Kind) error {
return &OverflowError{name, val, to}
}