this repo has no description
0
fork

Configure Feed

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

cmd/cue: skip over null when importing with --path

YAML format allows multiple documents to be embedded in a single file,
and it is common that a multiple documents file contains empty
documents whose value is null.

This change skips over null when it encounters an error during
importing with the --path flag.

Fixes #3464

Change-Id: I5f1756a109938d405682ece2f67437e7b831a6aa
Signed-off-by: haoqixu <hq.xu0o0@gmail.com>
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1202049
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Chief Cueckoo <chief.cueckoo@gmail.com>

authored by

haoqixu and committed by
Daniel Martí
31ab53b3 52606f9a

+50 -20
+8
cmd/cue/cmd/orphans.go
··· 189 189 filename := d.Filename() 190 190 191 191 index := newIndex() 192 + 193 + objsLoop: 192 194 for i, file := range objs { 193 195 if i == 0 { 194 196 astutil.CopyMeta(f, file) ··· 200 202 201 203 switch { 202 204 case len(b.path) > 0: 205 + 206 + lit, _ := expr.(*ast.BasicLit) 207 + isNull := lit != nil && lit.Value == "null" 203 208 expr := expr 204 209 if b.useContext { 205 210 expr = ast.NewStruct( ··· 251 256 default: 252 257 var arg interface{} = l 253 258 if err := l.Err(); err != nil { 259 + if isNull { 260 + continue objsLoop 261 + } 254 262 arg = err 255 263 } 256 264 return nil, fmt.Errorf(
+3 -6
cmd/cue/cmd/testdata/script/issue289.txtar
··· 1 - # TODO: error message could be improved. 2 - 3 - ! exec cue import test.yaml -p kube -l 'strings.ToCamel(kind)' -l metadata.name -f 4 - cmp stderr expect-stderr 1 + exec cue import test.yaml -p kube -l 'strings.ToCamel(kind)' -l metadata.name -f 2 + cmp stdout expect-stdout 5 3 6 4 -- test.yaml -- 7 5 apiVersion: v1 ··· 12 10 type: NodePort 13 11 --- 14 12 # EMPTY FILE 15 - -- expect-stderr -- 16 - error evaluating label strings.ToCamel(kind): reference "kind" not found 13 + -- expect-stdout --
+39 -14
cmd/cue/cmd/testdata/script/issue3464.txtar
··· 1 - exec cue import --outfile=- --list input-noempty.yaml 1 + exec cue import --outfile=- --list input-noempty.yaml 2 2 cmp stdout output-noempty-list.cue 3 - exec cue import --outfile=- --path=strings.ToLower(kind) input-noempty.yaml 3 + exec cue import --outfile=- --path=strings.ToLower(kind) input-noempty.yaml 4 4 cmp stdout output-noempty-exprpath.cue 5 - exec cue import --outfile=- --list --path=strings.ToLower(kind) input-noempty.yaml 5 + exec cue import --outfile=- --list --path=strings.ToLower(kind) input-noempty.yaml 6 6 cmp stdout output-noempty-list-exprpath.cue 7 - exec cue import --outfile=- --list --path=fixedpath: input-noempty.yaml 7 + exec cue import --outfile=- --list --path=fixedpath: input-noempty.yaml 8 8 cmp stdout output-noempty-list-fixedpath.cue 9 9 10 - exec cue import --outfile=- --list input-withempty.yaml 10 + exec cue import --outfile=- --list input-withempty.yaml 11 11 cmp stdout output-withempty-list.cue 12 - ! exec cue import --outfile=- --path=strings.ToLower(kind) input-withempty.yaml 12 + exec cue import --outfile=- --path=strings.ToLower(kind) input-withempty.yaml 13 13 cmp stdout output-withempty-exprpath.cue 14 - ! exec cue import --outfile=- --list --path=strings.ToLower(kind) input-withempty.yaml 14 + exec cue import --outfile=- --list --path=strings.ToLower(kind) input-withempty.yaml 15 15 cmp stdout output-withempty-list-exprpath.cue 16 - exec cue import --outfile=- --list --path=fixedpath: input-withempty.yaml 16 + exec cue import --outfile=- --list --path=fixedpath: input-withempty.yaml 17 17 cmp stdout output-withempty-list-fixedpath.cue 18 18 19 - exec cue import --outfile=- --list input-withnull.yaml 19 + exec cue import --outfile=- --list input-withnull.yaml 20 20 cmp stdout output-withnull-list.cue 21 - ! exec cue import --outfile=- --path=strings.ToLower(kind) input-withnull.yaml 21 + exec cue import --outfile=- --path=strings.ToLower(kind) input-withnull.yaml 22 22 cmp stdout output-withnull-exprpath.cue 23 - ! exec cue import --outfile=- --list --path=strings.ToLower(kind) input-withnull.yaml 23 + exec cue import --outfile=- --list --path=strings.ToLower(kind) input-withnull.yaml 24 24 cmp stdout output-withnull-list-exprpath.cue 25 - exec cue import --outfile=- --list --path=fixedpath: input-withnull.yaml 25 + exec cue import --outfile=- --list --path=fixedpath: input-withnull.yaml 26 26 cmp stdout output-withnull-list-fixedpath.cue 27 27 28 28 exec cue import --outfile=- --list input-missing-key.yaml ··· 36 36 ! exec cue import --outfile=- --path=strings.ToLower(typo) input-missing-key.yaml 37 37 cmp stdout output-missing-key-typopath.cue 38 38 39 - exec cue import --outfile=- --with-context --path='"number-\(index+1)"' input-withempty.yaml 39 + exec cue import --outfile=- --with-context --path='"number-\(index+1)"' input-withempty.yaml 40 40 cmp stdout output-withempty-witcontext-index.cue 41 - ! exec cue import --outfile=- --with-context --path='"number-\(index+1)"' --path=data.kind input-withempty.yaml 41 + exec cue import --outfile=- --with-context --path='"number-\(index+1)"' --path=data.kind input-withempty.yaml 42 42 cmp stdout output-withempty-witcontext-index-kind.cue 43 43 44 44 -- input-noempty.yaml -- ··· 94 94 kind: "Other" 95 95 }] 96 96 -- output-withempty-exprpath.cue -- 97 + deployment: kind: "Deployment" 98 + deployment: kind: "Deployment" 99 + other: kind: "Other" 97 100 -- output-withempty-list-exprpath.cue -- 101 + deployment: [{ 102 + kind: "Deployment" 103 + }, { 104 + kind: "Deployment" 105 + }] 106 + other: [{ 107 + kind: "Other" 108 + }] 98 109 -- output-withempty-list-fixedpath.cue -- 99 110 fixedpath: [{ 100 111 kind: "Deployment" ··· 121 132 kind: "Other" 122 133 }] 123 134 -- output-withnull-exprpath.cue -- 135 + deployment: kind: "Deployment" 136 + deployment: kind: "Deployment" 137 + other: kind: "Other" 124 138 -- output-withnull-list-exprpath.cue -- 139 + deployment: [{ 140 + kind: "Deployment" 141 + }, { 142 + kind: "Deployment" 143 + }] 144 + other: [{ 145 + kind: "Other" 146 + }] 125 147 -- output-withnull-list-fixedpath.cue -- 126 148 fixedpath: [{ 127 149 kind: "Deployment" ··· 168 190 "number-3": kind: "Deployment" 169 191 "number-4": kind: "Other" 170 192 -- output-withempty-witcontext-index-kind.cue -- 193 + "number-1": Deployment: kind: "Deployment" 194 + "number-3": Deployment: kind: "Deployment" 195 + "number-4": Other: kind: "Other"