-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
71 lines (60 loc) · 1.5 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package scss
import (
"fmt"
"github.com/thijzert/go-scss/lexer"
"strings"
)
type CompileError struct {
Message string
Previous error
}
type ParseError struct {
Message string
Previous error
LastToken *lexer.Token
}
func (p ParseError) Error() string {
return p.Message
}
func (p ParseError) Cause() error {
return p.Previous
}
func parseError(err string, cause error, lastToken *lexer.Token) error {
return ParseError{err, cause, lastToken}
}
func (p ParseError) String() string {
rv := p.Message
if p.LastToken != nil {
rv = fmt.Sprintf("%s -- at line %d c %d", p.Message, p.LastToken.Line, p.LastToken.Column)
}
if p.Previous != nil {
if perr, ok := p.Previous.(ParseError); ok {
return rv + "\n\t" + strings.Replace(perr.String(), "\n", "\n\t", -1)
} else {
return rv + "\n\t" + strings.Replace(p.Previous.Error(), "\n", "\n\t", -1)
}
}
return rv
}
func (p CompileError) Error() string {
return p.Message
}
func (p CompileError) Cause() error {
return p.Previous
}
func compileError(err string, cause error) error {
return CompileError{err, cause}
}
func (p CompileError) String() string {
rv := p.Message
if p.Previous != nil {
if perr, ok := p.Previous.(CompileError); ok {
return rv + "\n\t" + strings.Replace(perr.String(), "\n", "\n\t", -1)
} else if perr, ok := p.Previous.(ParseError); ok {
return rv + "\n\t" + strings.Replace(perr.String(), "\n", "\n\t", -1)
} else {
return rv + "\n\t" + strings.Replace(p.Previous.Error(), "\n", "\n\t", -1)
}
}
return rv
}