this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/flow: ignore faulty tasks outside the root

This may only occur with InferTasks, the use of which
is highly discouraged.

Fixes #608

Change-Id: I840534a913e03630caabf3eb58a10a93d51b5a18
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7943
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>

+53 -5
+20
cmd/cue/cmd/testdata/script/cmd_issue596.txt cmd/cue/cmd/testdata/script/cmd_inferred.txt
··· 3 3 -- f1.cue -- 4 4 package kube 5 5 6 + pkg: { 7 + #Def: { 8 + a: int 9 + b: #Role 10 + } 11 + #Role: { 12 + kind: string 13 + name: string 14 + } 15 + 16 + } 17 + 18 + test: pkg.#Def 6 19 test: { 7 20 a: 1 21 + b: { 22 + kind: "foo" 23 + name: "bar" 24 + } 8 25 } 9 26 10 27 // A kind at the top-level should not be allowed. ··· 26 43 27 44 -- expect-stdout -- 28 45 a: 1 46 + b: 47 + kind: foo 48 + name: bar 29 49
+3
tools/flow/flow_test.go
··· 101 101 return nil 102 102 }), nil 103 103 } 104 + if err != nil && v.Lookup("$id").Exists() { 105 + return nil, err 106 + } 104 107 105 108 case "valToOut": 106 109 return flow.RunnerFunc(func(t *flow.Task) error {
+21 -2
tools/flow/tasks.go
··· 99 99 100 100 var errs errors.Error 101 101 if err != nil { 102 - c.addErr(err, "invalid task") 103 - errs = errors.Promote(err, "create task") 102 + if !c.inRoot(w) { 103 + // Must be in InferTask mode. In this case we ignore the error. 104 + r = nil 105 + } else { 106 + c.addErr(err, "invalid task") 107 + errs = errors.Promote(err, "create task") 108 + } 104 109 } 105 110 106 111 if r != nil { ··· 222 227 } 223 228 return nil 224 229 }) 230 + } 231 + 232 + func (c *Controller) inRoot(n *adt.Vertex) bool { 233 + path := cue.MakeValue(c.opCtx, n).Path().Selectors() 234 + root := c.cfg.Root.Selectors() 235 + if len(path) < len(root) { 236 + return false 237 + } 238 + for i, sel := range root { 239 + if path[i] != sel { 240 + return false 241 + } 242 + } 243 + return true 225 244 } 226 245 227 246 var cycleMarker = &Task{}
+9 -3
tools/flow/testdata/infer.txtar
··· 8 8 $after: top0 9 9 } 10 10 11 + top3: { 12 + $id: string // not a task 13 + } 14 + 11 15 root: { 12 16 t1: { 13 17 $id: "valToOut" 14 - $after: top1 18 + $after: [top1, top3] 15 19 } 16 20 } 17 21 -- out/run/errors -- ··· 61 65 -- out/run/t3/value -- 62 66 { 63 67 $id: "valToOut" 64 - $after: { 68 + $after: [{ 65 69 $id: "valToOut" 66 70 $after: { 67 71 $id: "valToOut" 68 72 } 69 - } 73 + }, { 74 + $id: string 75 + }] 70 76 }