-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror.go
More file actions
54 lines (43 loc) · 1.22 KB
/
Copy patherror.go
File metadata and controls
54 lines (43 loc) · 1.22 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
package chaff
import (
"fmt"
)
type (
errorCollection struct {
referenceHandler *referenceHandler
documentResolver *documentResolver
Errors map[string]map[string]error
}
)
func newErrorCollection(
referenceHandler *referenceHandler,
documentResolver *documentResolver,
) *errorCollection {
return &errorCollection{
referenceHandler: referenceHandler,
documentResolver: documentResolver,
Errors: make(map[string]map[string]error),
}
}
func (ec *errorCollection) AddErrorWithSubpath(subPath string, err error) {
document, path := ec.documentResolver.GetDocumentIdCurrentlyBeingParsed(), ec.referenceHandler.CurrentPath
if _, exists := ec.Errors[document]; !exists {
ec.Errors[document] = make(map[string]error)
}
ec.Errors[document][path+subPath] = err
}
func (ec *errorCollection) AddError(err error) {
ec.AddErrorWithSubpath("", err)
}
func (ec *errorCollection) HasErrors() bool {
return len(ec.Errors) > 0
}
func (ec *errorCollection) CollectErrors() map[string]error {
flattenedErrors := make(map[string]error)
for doc, docErrors := range ec.Errors {
for path, err := range docErrors {
flattenedErrors[fmt.Sprintf("%s -> %s", doc, path)] = err
}
}
return flattenedErrors
}