9
9
10
10
// MultiError is a list of errors occured on parsing.
11
11
//
12
- // Note that `ParseXXX` methods returns this wrapped error even if the error is just one.
12
+ // Note that Parse* methods returns this wrapped error even if the error is just one.
13
13
type MultiError []* Error
14
14
15
15
func (list MultiError ) String () string {
@@ -27,21 +27,22 @@ func (list MultiError) Error() string {
27
27
case 1 :
28
28
return list [0 ].Error ()
29
29
case 2 :
30
- return list [0 ].Error () + "\n (and 1 other error)"
30
+ return list [0 ].Error () + " (and 1 other error)"
31
31
default :
32
- return fmt .Sprintf ("%s\n (and %d other errors)" , list [0 ].Error (), len (list ))
32
+ return fmt .Sprintf ("%s (and %d other errors)" , list [0 ].Error (), len (list )- 1 )
33
33
}
34
34
}
35
35
36
36
// FullError returns a full error message.
37
37
func (list MultiError ) FullError () string {
38
38
var message bytes.Buffer
39
39
for _ , err := range list {
40
- fmt .Fprintln (& message , err .Error ())
40
+ fmt .Fprintln (& message , err .FullError ())
41
41
}
42
42
return message .String ()
43
43
}
44
44
45
+ // Error is an error occured on parsing.
45
46
type Error struct {
46
47
Message string
47
48
Position * token.Position
@@ -51,9 +52,14 @@ func (e *Error) String() string {
51
52
return e .Error ()
52
53
}
53
54
55
+ // Error returns an error message.
54
56
func (e * Error ) Error () string {
57
+ return fmt .Sprintf ("syntax error: %s: %s" , e .Position , e .Message )
58
+ }
59
+
60
+ func (e * Error ) FullError () string {
55
61
var message bytes.Buffer
56
- fmt .Fprintf (& message , "syntax error: %s: %s" , e . Position , e . Message )
62
+ fmt .Fprint (& message , e . Error () )
57
63
if e .Position .Source != "" {
58
64
fmt .Fprintf (& message , "\n %s" , e .Position .Source )
59
65
}
0 commit comments