From 92dc8e2df2fb63b273e060a3da43e04c752c4fcb Mon Sep 17 00:00:00 2001 From: Nick Figgins Date: Sat, 24 Feb 2024 13:29:08 -0500 Subject: [PATCH] tools/flow: check and return errors from task values Currently if an identifier doesn't exist within a _tool.cue file, it's ignored and no error is thrown. This updates the logic in the flow controller to check and return errors from task values during initialization. Fixes #1581. Change-Id: Iaf1a6262b7f44b07525b9e56079b804047dada9d Signed-off-by: Nick Figgins --- .../cmd/testdata/script/cmd_undefined.txtar | 34 +++++++++++++++++++ tools/flow/tasks.go | 4 +++ tools/flow/testdata/issue2517.txtar | 7 ++-- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 cmd/cue/cmd/testdata/script/cmd_undefined.txtar diff --git a/cmd/cue/cmd/testdata/script/cmd_undefined.txtar b/cmd/cue/cmd/testdata/script/cmd_undefined.txtar new file mode 100644 index 00000000000..80236d7c250 --- /dev/null +++ b/cmd/cue/cmd/testdata/script/cmd_undefined.txtar @@ -0,0 +1,34 @@ +! exec cue cmd tool +stderr 'command.tool.bad: undefined field: DoesntExist' +! exec cue cmd builtin +stderr 'command.builtin.bad: undefined field: DoesntExist' +! exec cue cmd package +stderr 'command.package.bad: undefined field: DoesntExist' +-- cue.mod/module.cue -- +module: "mod.test/test" +-- sub/sub.cue -- +package sub +-- task_tool.cue -- +package home + +import ( + "tool/os" + "strconv" + "mod.test/test/sub" +) + +command: tool: { + bad: os.DoesntExist & { + input: "a" + } +} + +command: builtin: { + bad: strconv.DoesntExist & { + a: "b" + } +} + +command: package: { + bad: sub.DoesntExist +} diff --git a/tools/flow/tasks.go b/tools/flow/tasks.go index c9ba382b1dc..f110d1af744 100644 --- a/tools/flow/tasks.go +++ b/tools/flow/tasks.go @@ -91,6 +91,10 @@ func (c *Controller) findRootTasks(v cue.Value) { // getTask finds and marks tasks that are descendents of v. func (c *Controller) getTask(scope *Task, v cue.Value) *Task { + if err := v.Err(); err != nil { + c.addErr(err, "invalid task") + return nil + } // Look up cached node. _, w := value.ToInternal(v) if t, ok := c.nodes[w]; ok { diff --git a/tools/flow/testdata/issue2517.txtar b/tools/flow/testdata/issue2517.txtar index e5baa4d90e1..56caaf32487 100644 --- a/tools/flow/testdata/issue2517.txtar +++ b/tools/flow/testdata/issue2517.txtar @@ -6,6 +6,7 @@ package x root: { prepare: { $id: "prepare" + stdout: string } env2: { input: prepare.stdout @@ -41,7 +42,7 @@ Allocs: 5 Retain: 0 Unifications: 11 -Conjuncts: 17 +Conjuncts: 20 Disjuncts: 11 -- out/run/t2 -- graph TD @@ -65,7 +66,7 @@ Allocs: 0 Retain: 0 Unifications: 12 -Conjuncts: 21 +Conjuncts: 24 Disjuncts: 12 -- out/run/stats/totals -- Leaks: 0 @@ -75,5 +76,5 @@ Allocs: 5 Retain: 0 Unifications: 23 -Conjuncts: 38 +Conjuncts: 44 Disjuncts: 23