-
Notifications
You must be signed in to change notification settings - Fork 245
/
errors.go
76 lines (61 loc) · 2.17 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
72
73
74
75
76
package caveats
import (
"strconv"
"github.com/google/cel-go/cel"
"github.com/rs/zerolog"
)
// EvaluationErr is an error in evaluation of a caveat expression.
type EvaluationErr struct {
error
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler
func (err EvaluationErr) MarshalZerologObject(e *zerolog.Event) {
e.Err(err.error)
}
// DetailsMetadata returns the metadata for details for this error.
func (err EvaluationErr) DetailsMetadata() map[string]string {
return map[string]string{}
}
// ParameterConversionErr is an error in type conversion of a supplied parameter.
type ParameterConversionErr struct {
error
parameterName string
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler
func (err ParameterConversionErr) MarshalZerologObject(e *zerolog.Event) {
e.Err(err.error).Str("parameterName", err.parameterName)
}
// DetailsMetadata returns the metadata for details for this error.
func (err ParameterConversionErr) DetailsMetadata() map[string]string {
return map[string]string{
"parameter_name": err.parameterName,
}
}
// ParameterName is the name of the parameter.
func (err ParameterConversionErr) ParameterName() string {
return err.parameterName
}
// CompilationErrors is a wrapping error for containing compilation errors for a Caveat.
type CompilationErrors struct {
error
issues *cel.Issues
}
// LineNumber is the 0-indexed line number for compilation error.
func (err CompilationErrors) LineNumber() int {
return err.issues.Errors()[0].Location.Line() - 1
}
// ColumnPositionis the 0-indexed column position for compilation error.
func (err CompilationErrors) ColumnPosition() int {
return err.issues.Errors()[0].Location.Column() - 1
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler
func (err CompilationErrors) MarshalZerologObject(e *zerolog.Event) {
e.Err(err.error).Int("lineNumber", err.LineNumber()).Int("columnPosition", err.ColumnPosition())
}
// DetailsMetadata returns the metadata for details for this error.
func (err CompilationErrors) DetailsMetadata() map[string]string {
return map[string]string{
"line_number": strconv.Itoa(err.LineNumber()),
"column_position": strconv.Itoa(err.ColumnPosition()),
}
}