mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
PromQL: Use more standart format for error positions (#6433)
The most common format (used by go, gcc and clang) for compiler error positions seems to be `filename:line:char:` or `line:char:` if the filename is unknown. This PR adapts the PromQL parser to use this convention. Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
This commit is contained in:
parent
cd39ebe7c6
commit
35c1f31721
|
@ -53,10 +53,7 @@ type ParseErr struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ParseErr) Error() string {
|
func (e *ParseErr) Error() string {
|
||||||
if e.Line == 0 {
|
return fmt.Sprintf("%d:%d: parse error: %s", e.Line+1, e.Pos, e.Err)
|
||||||
return fmt.Sprintf("parse error at char %d: %s", e.Pos, e.Err)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("parse error at line %d, char %d: %s", e.Line, e.Pos, e.Err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseExpr returns the expression parsed from the input.
|
// ParseExpr returns the expression parsed from the input.
|
||||||
|
|
|
@ -219,7 +219,7 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: "1 == 1",
|
input: "1 == 1",
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 7: comparisons between scalars must use BOOL modifier",
|
errMsg: "1:7: parse error: comparisons between scalars must use BOOL modifier",
|
||||||
}, {
|
}, {
|
||||||
input: "1 or 1",
|
input: "1 or 1",
|
||||||
fail: true,
|
fail: true,
|
||||||
|
@ -255,7 +255,7 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: "a - on(b) ignoring(c) d",
|
input: "a - on(b) ignoring(c) d",
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 11: no valid expression found",
|
errMsg: "1:11: parse error: no valid expression found",
|
||||||
},
|
},
|
||||||
// Vector binary operations.
|
// Vector binary operations.
|
||||||
{
|
{
|
||||||
|
@ -919,7 +919,7 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: "some_metric{a=\"\xff\"}",
|
input: "some_metric{a=\"\xff\"}",
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 15: invalid UTF-8 rune",
|
errMsg: "1:15: parse error: invalid UTF-8 rune",
|
||||||
}, {
|
}, {
|
||||||
input: `foo{gibberish}`,
|
input: `foo{gibberish}`,
|
||||||
fail: true,
|
fail: true,
|
||||||
|
@ -1057,11 +1057,11 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: `some_metric OFFSET 1m[5m]`,
|
input: `some_metric OFFSET 1m[5m]`,
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 25: unexpected \"]\" in subquery selector, expected \":\"",
|
errMsg: "1:25: parse error: unexpected \"]\" in subquery selector, expected \":\"",
|
||||||
}, {
|
}, {
|
||||||
input: `(foo + bar)[5m]`,
|
input: `(foo + bar)[5m]`,
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 15: unexpected \"]\" in subquery selector, expected \":\"",
|
errMsg: "1:15: parse error: unexpected \"]\" in subquery selector, expected \":\"",
|
||||||
},
|
},
|
||||||
// Test aggregation.
|
// Test aggregation.
|
||||||
{
|
{
|
||||||
|
@ -1222,7 +1222,7 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: "MIN keep_common (some_metric)",
|
input: "MIN keep_common (some_metric)",
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 5: unexpected identifier \"keep_common\" in aggregation, expected \"(\"",
|
errMsg: "1:5: parse error: unexpected identifier \"keep_common\" in aggregation, expected \"(\"",
|
||||||
}, {
|
}, {
|
||||||
input: "MIN (some_metric) keep_common",
|
input: "MIN (some_metric) keep_common",
|
||||||
fail: true,
|
fail: true,
|
||||||
|
@ -1238,15 +1238,15 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: `topk(some_metric)`,
|
input: `topk(some_metric)`,
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 17: unexpected \")\" in aggregation, expected \",\"",
|
errMsg: "1:17: parse error: unexpected \")\" in aggregation, expected \",\"",
|
||||||
}, {
|
}, {
|
||||||
input: `topk(some_metric, other_metric)`,
|
input: `topk(some_metric, other_metric)`,
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 32: expected type scalar in aggregation parameter, got instant vector",
|
errMsg: "1:32: parse error: expected type scalar in aggregation parameter, got instant vector",
|
||||||
}, {
|
}, {
|
||||||
input: `count_values(5, other_metric)`,
|
input: `count_values(5, other_metric)`,
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 30: expected type string in aggregation parameter, got scalar",
|
errMsg: "1:30: parse error: expected type string in aggregation parameter, got scalar",
|
||||||
},
|
},
|
||||||
// Test function calls.
|
// Test function calls.
|
||||||
{
|
{
|
||||||
|
@ -1332,7 +1332,7 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: "label_replace(a, `b`, `c\xff`, `d`, `.*`)",
|
input: "label_replace(a, `b`, `c\xff`, `d`, `.*`)",
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 23: invalid UTF-8 rune",
|
errMsg: "1:23: parse error: invalid UTF-8 rune",
|
||||||
},
|
},
|
||||||
// Fuzzing regression tests.
|
// Fuzzing regression tests.
|
||||||
{
|
{
|
||||||
|
@ -1586,11 +1586,11 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: "test[5d] OFFSET 10s [10m:5s]",
|
input: "test[5d] OFFSET 10s [10m:5s]",
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 29: subquery is only allowed on instant vector, got matrix in \"test[5d] offset 10s[10m:5s]\"",
|
errMsg: "1:29: parse error: subquery is only allowed on instant vector, got matrix in \"test[5d] offset 10s[10m:5s]\"",
|
||||||
}, {
|
}, {
|
||||||
input: `(foo + bar{nm="val"})[5m:][10m:5s]`,
|
input: `(foo + bar{nm="val"})[5m:][10m:5s]`,
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 27: could not parse remaining input \"[10m:5s]\"...",
|
errMsg: "1:27: parse error: could not parse remaining input \"[10m:5s]\"...",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,13 @@ var scenarios = map[string]struct {
|
||||||
"invalid params from the beginning": {
|
"invalid params from the beginning": {
|
||||||
params: "match[]=-not-a-valid-metric-name",
|
params: "match[]=-not-a-valid-metric-name",
|
||||||
code: 400,
|
code: 400,
|
||||||
body: `parse error at char 1: vector selector must contain label matchers or metric name
|
body: `1:1: parse error: vector selector must contain label matchers or metric name
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
"invalid params somewhere in the middle": {
|
"invalid params somewhere in the middle": {
|
||||||
params: "match[]=not-a-valid-metric-name",
|
params: "match[]=not-a-valid-metric-name",
|
||||||
code: 400,
|
code: 400,
|
||||||
body: `parse error at char 4: could not parse remaining input "-a-valid-metric"...
|
body: `1:4: parse error: could not parse remaining input "-a-valid-metric"...
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
"test_metric1": {
|
"test_metric1": {
|
||||||
|
|
Loading…
Reference in a new issue