-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
50 lines (43 loc) · 862 Bytes
/
error.go
File metadata and controls
50 lines (43 loc) · 862 Bytes
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
package peony
import (
"fmt"
)
type Error struct {
Title string
FileName string
SourceLines []string
Path string
Line int
Column int
Description string
}
type sourceLine struct {
Source string
Line int
IsError bool
}
func (e *Error) ContextSource() []sourceLine {
if e.SourceLines == nil {
return nil
}
start := (e.Line - 1) - 5
if start < 0 {
start = 0
}
end := (e.Line - 1) + 5
if end > len(e.SourceLines) {
end = len(e.SourceLines)
}
if start > end {
start = end
}
var lines []sourceLine = make([]sourceLine, end-start)
for i, src := range e.SourceLines[start:end] {
fileLine := start + i + 1
lines[i] = sourceLine{src, fileLine, fileLine == e.Line}
}
return lines
}
func (e *Error) Error() string {
return fmt.Sprintf("%s:%d:%d: %s", e.FileName, e.Line, e.Column, e.Description)
}