-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
90 lines (70 loc) · 1.36 KB
/
error.go
File metadata and controls
90 lines (70 loc) · 1.36 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package markers
import (
"fmt"
"go/ast"
"go/token"
)
type Position struct {
Line int
Column int
}
type Error struct {
FileName string
Position Position
error
}
func NewError(err error, fileName string, position Position) error {
return Error{
fileName,
position,
err,
}
}
type ScannerError struct {
Message string
}
func (err ScannerError) Error() string {
return err.Message
}
type ImportError struct {
Marker string
}
func (err ImportError) Error() string {
return fmt.Sprintf("the marker '%s' cannot be resolved", err.Marker)
}
type ParserError struct {
FileName string
Position Position
error
}
type ErrorList []error
func NewErrorList(errors []error) error {
if len(errors) == 0 {
return nil
}
return ErrorList(errors)
}
func (errorList ErrorList) ToErrors() []error {
return errorList
}
func (errorList ErrorList) Error() string {
return fmt.Sprintf("%v", []error(errorList))
}
func toParseError(err error, node ast.Node, position token.Position) error {
errorList, ok := err.(ErrorList)
if !ok {
return ParserError{
FileName: position.Filename,
Position: Position{
Line: position.Line,
Column: position.Column,
},
error: err,
}
}
errors := make(ErrorList, len(errorList))
for index, errorElement := range errorList {
errors[index] = toParseError(errorElement, node, position)
}
return errors
}