From 360a47fddc28a451dcf5bd3720c33c7f44a2088d Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Wed, 15 Mar 2023 13:57:47 +1100 Subject: [PATCH] Fixed npe in log #1596 --- pkg/yqlib/operator_variables.go | 3 ++- pkg/yqlib/operator_variables_test.go | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/operator_variables.go b/pkg/yqlib/operator_variables.go index d9baded9..32248ffc 100644 --- a/pkg/yqlib/operator_variables.go +++ b/pkg/yqlib/operator_variables.go @@ -82,10 +82,11 @@ func variableLoopSingleChild(d *dataTreeNavigator, context Context, originalExp newContext.SetVariable(variableName, variableValue) rhs, err := d.GetMatchingNodes(newContext, originalExp.RHS) - log.Debug("PROCESSING VARIABLE DONE, got back: ", rhs.MatchingNodes.Len()) + if err != nil { return Context{}, err } + log.Debug("PROCESSING VARIABLE DONE, got back: ", rhs.MatchingNodes.Len()) results.PushBackList(rhs.MatchingNodes) } diff --git a/pkg/yqlib/operator_variables_test.go b/pkg/yqlib/operator_variables_test.go index 64643ab0..f1555f28 100644 --- a/pkg/yqlib/operator_variables_test.go +++ b/pkg/yqlib/operator_variables_test.go @@ -13,6 +13,12 @@ var variableOperatorScenarios = []expressionScenario{ "D0, P[], (doc)::{}\n", }, }, + { + skipDoc: true, + document: `{}`, + expression: `.a.b as $foo`, + expectedError: "must use variable with a pipe, e.g. `exp as $x | ...`", + }, { document: "a: [cat]", skipDoc: true,