From c7b3869b2f8689f3f95d3813c374e580f4976765 Mon Sep 17 00:00:00 2001 From: Ed <3950058+edtan@users.noreply.github.com> Date: Mon, 18 Jan 2021 14:44:27 -0500 Subject: [PATCH] Report error when `if` expression is invalid (#485) Co-authored-by: Ed Tan Co-authored-by: Casey Lee --- pkg/runner/run_context.go | 2 +- pkg/runner/run_context_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index f0cd0c5..43ec4d5 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -314,7 +314,7 @@ func (rc *RunContext) EvalBool(expr string) (bool, error) { joined := strings.Join(evaluatedParts, " ") v, _, err := rc.ExprEval.Evaluate(fmt.Sprintf("Boolean(%s)", joined)) if err != nil { - return false, nil + return false, err } log.Debugf("expression '%s' evaluated to '%s'", expr, v) return v == "true", nil diff --git a/pkg/runner/run_context_test.go b/pkg/runner/run_context_test.go index fd9de7e..01dab5e 100644 --- a/pkg/runner/run_context_test.go +++ b/pkg/runner/run_context_test.go @@ -2,13 +2,14 @@ package runner import ( "fmt" - "github.com/nektos/act/pkg/model" - a "github.com/stretchr/testify/assert" "os" "regexp" "strings" "testing" + "github.com/nektos/act/pkg/model" + a "github.com/stretchr/testify/assert" + "github.com/sirupsen/logrus/hooks/test" ) @@ -129,6 +130,8 @@ func TestRunContext_EvalBool(t *testing.T) { // The special ACT flag {in: "${{ env.ACT }}", out: true}, {in: "${{ !env.ACT }}", out: false}, + // Invalid expressions should be reported + {in: "INVALID_EXPRESSION", wantErr: true}, } updateTestIfWorkflow(t, tables, rc)