-
Notifications
You must be signed in to change notification settings - Fork 248
/
errors.go
53 lines (44 loc) · 1.26 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
package compiler
import (
"strconv"
"github.com/authzed/spicedb/pkg/schemadsl/input"
)
// BaseCompilerError defines an error with contains the base message of the issue
// that occurred.
type BaseCompilerError struct {
error
BaseMessage string
}
type errorWithNode struct {
error
node *dslNode
errorSourceCode string
}
// ErrorWithContext defines an error which contains contextual information.
type ErrorWithContext struct {
BaseCompilerError
SourceRange input.SourceRange
Source input.Source
ErrorSourceCode string
}
func (ewc ErrorWithContext) Unwrap() error {
return ewc.BaseCompilerError
}
// DetailsMetadata returns the metadata for details for this error.
func (ewc ErrorWithContext) DetailsMetadata() map[string]string {
startLine, startCol, err := ewc.SourceRange.Start().LineAndColumn()
if err != nil {
return map[string]string{}
}
endLine, endCol, err := ewc.SourceRange.End().LineAndColumn()
if err != nil {
return map[string]string{}
}
return map[string]string{
"start_line_number": strconv.Itoa(startLine),
"start_column_position": strconv.Itoa(startCol),
"end_line_number": strconv.Itoa(endLine),
"end_column_position": strconv.Itoa(endCol),
"source_code": ewc.ErrorSourceCode,
}
}