-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
error.go
97 lines (82 loc) · 2.57 KB
/
error.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package logqlmodel
import (
"errors"
"fmt"
"github.com/prometheus/prometheus/model/labels"
)
// Those errors are useful for comparing error returned by the engine.
// e.g. errors.Is(err,logqlmodel.ErrParse) let you know if this is a ast parsing error.
var (
ErrParse = errors.New("failed to parse the log query")
ErrPipeline = errors.New("failed execute pipeline")
ErrLimit = errors.New("limit reached while evaluating the query")
ErrIntervalLimit = errors.New("[interval] value exceeds limit")
ErrBlocked = errors.New("query blocked by policy")
ErrParseMatchers = errors.New("only label matchers are supported")
ErrorLabel = "__error__"
PreserveErrorLabel = "__preserve_error__"
ErrorDetailsLabel = "__error_details__"
)
// ParseError is what is returned when we failed to parse.
type ParseError struct {
msg string
line, col int
}
func (p ParseError) Error() string {
if p.col == 0 && p.line == 0 {
return fmt.Sprintf("parse error : %s", p.msg)
}
return fmt.Sprintf("parse error at line %d, col %d: %s", p.line, p.col, p.msg)
}
// Is allows to use errors.Is(err,ErrParse) on this error.
func (p ParseError) Is(target error) bool {
return target == ErrParse
}
func NewParseError(msg string, line, col int) ParseError {
return ParseError{
msg: msg,
line: line,
col: col,
}
}
func NewStageError(expr string, err error) ParseError {
return ParseError{
msg: fmt.Sprintf(`stage '%s' : %s`, expr, err),
line: 0,
col: 0,
}
}
type PipelineError struct {
metric labels.Labels
errorType string
}
func NewPipelineErr(metric labels.Labels) *PipelineError {
return &PipelineError{
metric: metric,
errorType: metric.Get(ErrorLabel),
}
}
func (e PipelineError) Error() string {
return fmt.Sprintf(
"pipeline error: '%s' for series: '%s'.\n"+
"Use a label filter to intentionally skip this error. (e.g | __error__!=\"%s\").\n"+
"To skip all potential errors you can match empty errors.(e.g __error__=\"\")\n"+
"The label filter can also be specified after unwrap. (e.g | unwrap latency | __error__=\"\" )\n",
e.errorType, e.metric, e.errorType)
}
// Is allows to use errors.Is(err,ErrPipeline) on this error.
func (e PipelineError) Is(target error) bool {
return target == ErrPipeline
}
type LimitError struct {
error
}
func NewSeriesLimitError(limit int) *LimitError {
return &LimitError{
error: fmt.Errorf("maximum of series (%d) reached for a single query", limit),
}
}
// Is allows to use errors.Is(err,ErrLimit) on this error.
func (e LimitError) Is(target error) bool {
return target == ErrLimit
}