Skip to content

Commit

Permalink
tools/flow: check and return errors from task values
Browse files Browse the repository at this point in the history
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 <figginsn@gmail.com>
  • Loading branch information
nickfiggins committed Feb 25, 2024
1 parent ff8d497 commit 92dc8e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
34 changes: 34 additions & 0 deletions cmd/cue/cmd/testdata/script/cmd_undefined.txtar
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions tools/flow/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions tools/flow/testdata/issue2517.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package x
root: {
prepare: {
$id: "prepare"
stdout: string
}
env2: {
input: prepare.stdout
Expand Down Expand Up @@ -41,7 +42,7 @@ Allocs: 5
Retain: 0

Unifications: 11
Conjuncts: 17
Conjuncts: 20
Disjuncts: 11
-- out/run/t2 --
graph TD
Expand All @@ -65,7 +66,7 @@ Allocs: 0
Retain: 0

Unifications: 12
Conjuncts: 21
Conjuncts: 24
Disjuncts: 12
-- out/run/stats/totals --
Leaks: 0
Expand All @@ -75,5 +76,5 @@ Allocs: 5
Retain: 0

Unifications: 23
Conjuncts: 38
Conjuncts: 44
Disjuncts: 23

0 comments on commit 92dc8e2

Please sign in to comment.