this repo has no description
0
fork

Configure Feed

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

cmd/cue: fix spurious errors

Schema validation is sometimes too strict resulting in the
reporting of spurious errors. Disable schema checking for
now.
Note that any errors in the schema will anyway surface when
unified with the data instance.

Fixes #1479

Signed-off-by: Marcel van Lohuizen <mpvl@golang.org>

Change-Id: I2336f8453ee448c80c482e4eb19e0a99fd84d1a0
Signed-off-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/531263
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>

authored by

Marcel van Lohuizen and committed by
Marcel van Lohuizen
04812bfb 2fe5251e

+92 -9
+19 -6
cmd/cue/cmd/common.go
··· 168 168 case len(b.insts) > 0: 169 169 i = &instanceIterator{ 170 170 inst: b.instance, 171 - a: buildInstances(b.cmd, b.insts), 171 + a: buildInstances(b.cmd, b.insts, false), 172 172 i: -1, 173 173 } 174 174 default: ··· 303 303 if i.e == nil { 304 304 i.v = i.v.Unify(schema) // TODO(required fields): don't merge in schema 305 305 i.e = i.v.Err() 306 + } 307 + if i.e != nil { 308 + if err = i.v.Validate(); err != nil { 309 + // Validate should always be non-nil, but just in case. 310 + i.e = err 311 + } 306 312 } 307 313 i.f = nil 308 314 } ··· 620 626 } 621 627 622 628 if schema != nil && len(schema.Files) > 0 { 623 - inst := buildInstances(p.cmd, []*build.Instance{schema})[0] 629 + // TODO: ignore errors here for now until reporting of concreteness 630 + // of errors is correct. 631 + // See https://github.com/cue-lang/cue/issues/1483. 632 + inst := buildInstances( 633 + p.cmd, 634 + []*build.Instance{schema}, 635 + true)[0] 624 636 625 637 if inst.Err != nil { 626 638 return nil, err ··· 630 642 if p.schema != nil { 631 643 v := inst.Eval(p.schema) 632 644 if err := v.Err(); err != nil { 633 - return nil, err 645 + return nil, v.Validate() 634 646 } 635 647 p.encConfig.Schema = v 636 648 } ··· 715 727 return nil 716 728 } 717 729 718 - func buildInstances(cmd *Command, binst []*build.Instance) []*cue.Instance { 730 + func buildInstances(cmd *Command, binst []*build.Instance, ignoreErrors bool) []*cue.Instance { 719 731 // TODO: 720 732 // If there are no files and User is true, then use those? 721 733 // Always use all files in user mode? ··· 726 738 exitIfErr(cmd, inst, inst.Err, true) 727 739 } 728 740 729 - if flagIgnore.Bool(cmd) { 741 + // TODO: remove ignoreErrors flag and always return here, leaving it up to 742 + // clients to check for errors down the road. 743 + if ignoreErrors || flagIgnore.Bool(cmd) { 730 744 return instances 731 745 } 732 746 733 - // TODO check errors after the fact in case of ignore. 734 747 for _, inst := range instances { 735 748 // TODO: consider merging errors of multiple files, but ensure 736 749 // duplicates are removed.
+1
cmd/cue/cmd/custom.go
··· 202 202 // Verify entry against template. 203 203 v = value.UnifyBuiltin(v, kind) 204 204 if err := v.Err(); err != nil { 205 + err = v.Validate() 205 206 return nil, errors.Promote(err, "newTask") 206 207 } 207 208
+1 -1
cmd/cue/cmd/eval.go
··· 145 145 } 146 146 if err := v.Err(); err != nil { 147 147 errHeader() 148 - return err 148 + return v.Validate(syn...) 149 149 } 150 150 151 151 // TODO(#553): this can be removed once v.Syntax() below retains line
+7
cmd/cue/cmd/testdata/script/eval_flags.txt
··· 45 45 reference "#D1" not found: 46 46 --schema:1:1 47 47 -- expect-stderr5 -- 48 + field not allowed: Z: 49 + ./test.json:4:3 50 + ./vector.cue:3:1 51 + ./vector.cue:3:6 48 52 X: conflicting values 1 and float (mismatched types int and float): 49 53 ./test.json:2:8 50 54 ./vector.cue:4:8 55 + Y: conflicting values 2 and float (mismatched types int and float): 56 + ./test.json:3:8 57 + ./vector.cue:5:8
+62
cmd/cue/cmd/testdata/script/eval_mixedfiletypes.txt
··· 1 + #Issue 1479 2 + 3 + exec cue eval x.cue data.json y.cue 4 + 5 + 6 + # Demonstrate checks are ok 7 + exec cue eval x.cue data.json 8 + cmp stdout stdout.golden 9 + 10 + # Import JSON and verify that we can assert checks are ok 11 + exec cue import data.json 12 + exec cue eval x.cue data.cue y.cue 13 + 14 + # Assert checks ok using CUE + JSON 15 + exec cue eval x.cue data.json y.cue 16 + 17 + -- data.json -- 18 + { 19 + "team": { 20 + "alice": [ 21 + "EM" 22 + ], 23 + "bob": [ 24 + "TL" 25 + ] 26 + } 27 + } 28 + -- x.cue -- 29 + import ( 30 + "list" 31 + ) 32 + 33 + #Team: [string]: [...("EM" | "IC" | "TL")] 34 + 35 + team: #Team 36 + 37 + checks: { 38 + enoughMembers: { 39 + ok: len(team) >= 1 40 + } 41 + 42 + hasManager: { 43 + ok: len([ for m in team if list.Contains(m, "EM") {m}]) >= 1 44 + } 45 + } 46 + -- y.cue -- 47 + checks: [string]: ok: true 48 + 49 + -- stdout.golden -- 50 + #Team: {} 51 + team: { 52 + alice: ["EM"] 53 + bob: ["TL"] 54 + } 55 + checks: { 56 + enoughMembers: { 57 + ok: true 58 + } 59 + hasManager: { 60 + ok: true 61 + } 62 + }
+2 -2
cmd/cue/cmd/trim.go
··· 97 97 if binst == nil { 98 98 return nil 99 99 } 100 - instances := buildInstances(cmd, binst) 100 + instances := buildInstances(cmd, binst, false) 101 101 102 102 dst := flagOutFile.String(cmd) 103 103 if dst != "" && dst != "-" && !flagForce.Bool(cmd) { ··· 127 127 128 128 cfg := *defaultConfig.loadCfg 129 129 cfg.Overlay = overlay 130 - tinsts := buildInstances(cmd, load.Instances(args, &cfg)) 130 + tinsts := buildInstances(cmd, load.Instances(args, &cfg), false) 131 131 if len(tinsts) != len(binst) { 132 132 return errors.New("unexpected number of new instances") 133 133 }