diff --git a/cmd/webhook/admission/admission_test.go b/cmd/webhook/admission/admission_test.go index a2ad4b26da..3ab47c2c30 100644 --- a/cmd/webhook/admission/admission_test.go +++ b/cmd/webhook/admission/admission_test.go @@ -107,7 +107,7 @@ func TestRouteGroupAdmitter(t *testing.T) { { name: "invalid eskip filters", inputFile: "rg-with-invalid-eskip-filters.json", - message: "parse failed after token status, last route id: , position 11: syntax error", + message: "parse failed after token status, position 11: syntax error", }, { name: "valid eskip predicates", @@ -116,12 +116,12 @@ func TestRouteGroupAdmitter(t *testing.T) { { name: "invalid eskip predicates", inputFile: "rg-with-invalid-eskip-predicates.json", - message: "parse failed after token Method, last route id: Method, position 6: syntax error", + message: "parse failed after token Method, position 6: syntax error", }, { name: "invalid eskip filters and predicates", inputFile: "rg-with-invalid-eskip-filters-and-predicates.json", - message: "parse failed after token status, last route id: , position 11: syntax error\\nparse failed after token Method, last route id: Method, position 6: syntax error", + message: "parse failed after token status, position 11: syntax error\\nparse failed after token Method, position 6: syntax error", }, { name: "invalid routgroup multiple filters per json/yaml array item", @@ -180,12 +180,12 @@ func TestIngressAdmitter(t *testing.T) { { name: "invalid eskip filters", inputFile: "invalid-filters.json", - message: `invalid \"zalando.org/skipper-filter\" annotation: parse failed after token this, last route id: , position 9: syntax error`, + message: `invalid \"zalando.org/skipper-filter\" annotation: parse failed after token this, position 9: syntax error`, }, { name: "invalid eskip predicates", inputFile: "invalid-predicates.json", - message: `invalid \"zalando.org/skipper-predicate\" annotation: parse failed after token ), last route id: , position 15: syntax error`, + message: `invalid \"zalando.org/skipper-predicate\" annotation: parse failed after token ), position 15: syntax error`, }, { name: "invalid eskip routes", @@ -195,7 +195,7 @@ func TestIngressAdmitter(t *testing.T) { { name: "invalid eskip filters and predicates", inputFile: "invalid-filters-and-predicates.json", - message: `invalid \"zalando.org/skipper-filter\" annotation: parse failed after token this, last route id: , position 9: syntax error\ninvalid \"zalando.org/skipper-predicate\" annotation: parse failed after token ), last route id: , position 15: syntax error`, + message: `invalid \"zalando.org/skipper-filter\" annotation: parse failed after token this, position 9: syntax error\ninvalid \"zalando.org/skipper-predicate\" annotation: parse failed after token ), position 15: syntax error`, }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/config/config_test.go b/config/config_test.go index 2eeecba8da..c875bc6565 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -276,7 +276,7 @@ func Test_Validate(t *testing.T) { c.KubernetesEastWestRangePredicatesString = "WrongEastWestMode" }, wantErr: true, - want: errors.New("invalid east-west-range-predicates: parse failed after token ->, last route id: WrongEastWestMode, position 20: syntax error"), + want: errors.New("invalid east-west-range-predicates: parse failed after token ->, position 20: syntax error"), }, { name: "test wrong HistoGramBuckets", diff --git a/dataclients/kubernetes/testdata/routegroups/convert/failing-filter.log b/dataclients/kubernetes/testdata/routegroups/convert/failing-filter.log index 65bef8d5c6..b90ceb446a 100644 --- a/dataclients/kubernetes/testdata/routegroups/convert/failing-filter.log +++ b/dataclients/kubernetes/testdata/routegroups/convert/failing-filter.log @@ -1 +1 @@ -\[routegroup\] parse failed after token foo, last route id: , position 8: syntax error +\[routegroup\] parse failed after token foo, position 8: syntax error diff --git a/dataclients/kubernetes/testdata/routegroups/convert/failing-predicate.log b/dataclients/kubernetes/testdata/routegroups/convert/failing-predicate.log index 927c39515a..79e38a257c 100644 --- a/dataclients/kubernetes/testdata/routegroups/convert/failing-predicate.log +++ b/dataclients/kubernetes/testdata/routegroups/convert/failing-predicate.log @@ -1 +1 @@ -\[routegroup\] parse failed after token Header, last route id: Header, position 6: syntax error +\[routegroup\] parse failed after token Header, position 6: syntax error diff --git a/dataclients/kubernetes/testdata/routegroups/convert/no-catchall-for-failed-route-group.log b/dataclients/kubernetes/testdata/routegroups/convert/no-catchall-for-failed-route-group.log index 65bef8d5c6..b90ceb446a 100644 --- a/dataclients/kubernetes/testdata/routegroups/convert/no-catchall-for-failed-route-group.log +++ b/dataclients/kubernetes/testdata/routegroups/convert/no-catchall-for-failed-route-group.log @@ -1 +1 @@ -\[routegroup\] parse failed after token foo, last route id: , position 8: syntax error +\[routegroup\] parse failed after token foo, position 8: syntax error diff --git a/dataclients/kubernetes/testdata/routegroups/convert/single-failing-route-makes-the-group-fail.log b/dataclients/kubernetes/testdata/routegroups/convert/single-failing-route-makes-the-group-fail.log index e3fc6060a0..ba158256c3 100644 --- a/dataclients/kubernetes/testdata/routegroups/convert/single-failing-route-makes-the-group-fail.log +++ b/dataclients/kubernetes/testdata/routegroups/convert/single-failing-route-makes-the-group-fail.log @@ -1 +1 @@ -\[routegroup\] parse failed after token foo, last route id: foo, position 3: syntax error +\[routegroup\] parse failed after token foo, position 3: syntax error diff --git a/eskip/eskip_test.go b/eskip/eskip_test.go index 2324285276..85d002b336 100644 --- a/eskip/eskip_test.go +++ b/eskip/eskip_test.go @@ -163,8 +163,7 @@ func TestParse(t *testing.T) { "syntax without id", `* -> #`, nil, - // TODO: remove empty last route id - "parse failed after token ->, last route id: , position 5: syntax error", + "parse failed after token ->, position 5: syntax error", }} { t.Run(ti.msg, func(t *testing.T) { routes, err := Parse(ti.expression) @@ -220,14 +219,14 @@ func TestParseFilters(t *testing.T) { "error", "trallala", nil, - // TODO: remove empty last route id and fix position - "parse failed after token ->, last route id: , position 16: syntax error", + // TODO: fix position + "parse failed after token ->, position 16: syntax error", }, { "error 2", "foo-bar", nil, - // TODO: remove empty last route id and fix position - "parse failed after token foo, last route id: , position 8: syntax error", + // TODO: fix position + "parse failed after token foo, position 8: syntax error", }, { "success", `filter1(3.14) -> filter2("key", 42)`, @@ -259,13 +258,11 @@ func TestParsePredicates(t *testing.T) { }, { title: "invalid", input: `not predicates`, - // TODO: fix wrong last route id - err: "parse failed after token predicates, last route id: not, position 14: syntax error", + err: "parse failed after token predicates, position 14: syntax error", }, { title: "invalid", input: `Header#`, - // TODO: fix wrong last route id - err: "parse failed after token Header, last route id: Header, position 6: syntax error", + err: "parse failed after token Header, position 6: syntax error", }, { title: "single predicate", input: `Foo("bar")`, diff --git a/eskip/lexer.go b/eskip/lexer.go index 4100870073..c49942f190 100644 --- a/eskip/lexer.go +++ b/eskip/lexer.go @@ -367,7 +367,11 @@ func (l *eskipLex) Lex(lval *eskipSymType) int { } func (l *eskipLex) Error(err string) { + lastRouteID := "" + if l.lastRouteID != "" { + lastRouteID = ", last route id: " + l.lastRouteID + } l.err = fmt.Errorf( - "parse failed after token %s, last route id: %v, position %d: %s", - l.lastToken, l.lastRouteID, l.initialLength-len(l.code), err) + "parse failed after token %s%s, position %d: %s", + l.lastToken, lastRouteID, l.initialLength-len(l.code), err) } diff --git a/eskip/parser.go b/eskip/parser.go index cf322afbee..569ff7f323 100644 --- a/eskip/parser.go +++ b/eskip/parser.go @@ -93,30 +93,30 @@ var eskipExca = [...]int8{ const eskipPrivate = 57344 -const eskipLast = 62 +const eskipLast = 64 var eskipAct = [...]int8{ - 34, 40, 32, 31, 24, 17, 20, 21, 22, 25, - 27, 26, 19, 48, 36, 9, 37, 25, 41, 9, - 16, 25, 25, 3, 10, 7, 14, 42, 29, 43, - 4, 55, 8, 45, 44, 49, 45, 30, 28, 19, - 50, 15, 13, 47, 46, 38, 23, 51, 52, 39, - 53, 42, 54, 12, 35, 11, 33, 18, 5, 6, - 2, 1, + 34, 40, 32, 31, 26, 19, 22, 23, 24, 27, + 29, 28, 21, 48, 36, 9, 37, 27, 41, 9, + 18, 27, 27, 7, 10, 49, 43, 15, 14, 42, + 16, 16, 8, 55, 4, 45, 30, 50, 44, 21, + 45, 15, 3, 47, 46, 17, 38, 51, 52, 13, + 53, 42, 54, 12, 25, 11, 39, 35, 33, 20, + 5, 6, 2, 1, } var eskipPact = [...]int16{ - 14, -1000, 11, -1000, -1000, 49, 34, -1000, 15, -1000, - 2, -8, 10, 10, 4, -1000, -1000, -1000, 39, -1000, - -1000, -1000, -1000, -1000, -1000, -1000, 0, 18, -1000, 15, - -1000, 27, -1000, -1000, -1000, -1000, -1000, -1000, -8, -7, - 26, 31, -1000, 4, -1000, 4, -1000, -1000, -1000, 5, - 5, 24, -1000, -1000, 26, -1000, + 14, -1000, 11, -1000, -1000, 49, 10, -1000, 19, -1000, + 2, -8, 10, -1000, 20, -1000, 4, -1000, 33, -1000, + 40, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 0, 15, + -1000, 31, -1000, -1000, -1000, -1000, -1000, -1000, -8, -7, + 16, 28, -1000, 4, -1000, 4, -1000, -1000, -1000, 5, + 5, 26, -1000, -1000, 16, -1000, } var eskipPgo = [...]int8{ - 0, 61, 60, 23, 30, 59, 58, 5, 57, 25, - 3, 4, 2, 56, 0, 54, 1, 49, 46, + 0, 63, 62, 42, 34, 61, 60, 5, 59, 23, + 3, 4, 2, 58, 0, 57, 1, 56, 54, } var eskipR1 = [...]int8{ @@ -127,7 +127,7 @@ var eskipR1 = [...]int8{ } var eskipR2 = [...]int8{ - 0, 1, 1, 0, 1, 3, 2, 3, 1, 3, + 0, 1, 1, 0, 1, 3, 2, 2, 2, 3, 5, 1, 3, 1, 4, 1, 3, 4, 0, 1, 3, 1, 1, 1, 1, 3, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, @@ -135,18 +135,18 @@ var eskipR2 = [...]int8{ var eskipChk = [...]int16{ -1000, -1, -2, -3, -4, -6, -5, -9, 18, 5, - 13, 6, 4, 8, 11, -4, 18, -7, -8, -14, - 14, 15, 16, -18, -11, 17, 19, 18, -9, 18, - -3, -10, -12, -13, -14, -15, 10, 12, 6, -17, + 13, 6, 4, -3, 18, 8, 11, -4, 18, -7, + -8, -14, 14, 15, 16, -18, -11, 17, 19, 18, + -9, -10, -12, -13, -14, -15, 10, 12, 6, -17, -16, 18, -14, 11, 7, 9, -7, -11, 20, 9, 9, -10, -12, -14, -16, 7, } var eskipDef = [...]int8{ - 3, -2, 1, 2, 4, 0, 0, 11, 8, 13, - 6, 0, 0, 0, 18, 5, 8, 9, 0, 29, - 30, 31, 32, 33, 15, 35, 0, 0, 12, 0, - 7, 0, 19, 21, 22, 23, 34, 36, 0, 0, + 3, -2, 1, 2, 4, 0, 0, 11, 0, 13, + 6, 0, 0, 7, 0, 8, 18, 5, 0, 9, + 0, 29, 30, 31, 32, 33, 15, 35, 0, 0, + 12, 0, 19, 21, 22, 23, 34, 36, 0, 0, 26, 0, 24, 18, 14, 0, 10, 16, 28, 0, 0, 0, 20, 25, 27, 17, } @@ -528,14 +528,15 @@ eskipdefault: eskipVAL.routes = eskipDollar[1].routes } case 7: - eskipDollar = eskipS[eskippt-3 : eskippt+1] + eskipDollar = eskipS[eskippt-2 : eskippt+1] { - eskipVAL.route = eskipDollar[3].route + eskipVAL.route = eskipDollar[2].route eskipVAL.route.id = eskipDollar[1].token } case 8: - eskipDollar = eskipS[eskippt-1 : eskippt+1] + eskipDollar = eskipS[eskippt-2 : eskippt+1] { + // match symbol and colon to get route id early even if route parsing fails later eskipVAL.token = eskipDollar[1].token eskiplex.(*eskipLex).lastRouteID = eskipDollar[1].token } diff --git a/eskip/parser.y b/eskip/parser.y index 14061b2ddf..86a7048d23 100644 --- a/eskip/parser.y +++ b/eskip/parser.y @@ -98,13 +98,14 @@ routes: } routedef: - routeid colon route { - $$.route = $3.route + routeid route { + $$.route = $2.route $$.route.id = $1.token } routeid: - symbol { + symbol colon { + // match symbol and colon to get route id early even if route parsing fails later $$.token = $1.token eskiplex.(*eskipLex).lastRouteID = $1.token }