blob: 9c496096cf8da8329bd16e4e3a315b5546864805 (
plain)
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/authzed/cel-go/cel"
"github.com/rs/zerolog"
)
// EvaluationError is an error in evaluation of a caveat expression.
type EvaluationError struct {
error
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler
func (err EvaluationError) MarshalZerologObject(e *zerolog.Event) {
e.Err(err.error)
}
// DetailsMetadata returns the metadata for details for this error.
func (err EvaluationError) DetailsMetadata() map[string]string {
return map[string]string{}
}
// ParameterConversionError is an error in type conversion of a supplied parameter.
type ParameterConversionError struct {
error
parameterName string
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler
func (err ParameterConversionError) MarshalZerologObject(e *zerolog.Event) {
e.Err(err.error).Str("parameterName", err.parameterName)
}
// DetailsMetadata returns the metadata for details for this error.
func (err ParameterConversionError) DetailsMetadata() map[string]string {
return map[string]string{
"parameter_name": err.parameterName,
}
}
// ParameterName is the name of the parameter.
func (err ParameterConversionError) ParameterName() string {
return err.parameterName
}
// MultipleCompilationError is a wrapping error for containing compilation errors for a Caveat.
type MultipleCompilationError struct {
error
issues *cel.Issues
}
// LineNumber is the 0-indexed line number for compilation error.
func (err MultipleCompilationError) LineNumber() int {
return err.issues.Errors()[0].Location.Line() - 1
}
// ColumnPositionis the 0-indexed column position for compilation error.
func (err MultipleCompilationError) ColumnPosition() int {
return err.issues.Errors()[0].Location.Column() - 1
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler
func (err MultipleCompilationError) 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 MultipleCompilationError) DetailsMetadata() map[string]string {
return map[string]string{
"line_number": strconv.Itoa(err.LineNumber()),
"column_position": strconv.Itoa(err.ColumnPosition()),
}
}
|