this repo has no description
0
fork

Configure Feed

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

cue/load: do not panic when load.Instances(args, nil) fails very early

The function wouldn't initialize a nil config until later on,
and Config.newErrInstance assumed that the receiver was never nil.

Note that newErrInstance is already OK with any of its fields being nil,
such as the Context, which we only initialize later on in Instances.
That's fine, and does not need any adjustment.

We also don't move Config.complete further up in Instances,
again because it's unnecessary, but also to keep the same order
of which checks are done in which order to report errors to the user.

Fixes #4286.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I262cfc9e5def463789af4e8a291060d3d79bf75e
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1232122
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+6 -4
+1 -1
cmd/cue/cmd/testdata/script/get_crd_errors.txtar
··· 25 25 26 26 # Test CRD with the group as the argument rather than the file 27 27 ! exec cue get crd example.com 28 - stderr 'panic: runtime error: invalid memory address or nil pointer dereference' 28 + stderr 'unknown file extension \.com' 29 29 30 30 -- sample-crd.yaml -- 31 31 apiVersion: apiextensions.k8s.io/v1
+5 -3
cue/load/instances.go
··· 46 46 if len(args) == 0 { 47 47 args = []string{"."} 48 48 } 49 + // Note that Config is used early on to return error instances; ensure it's not nil. 50 + if c == nil { 51 + c = &Config{} 52 + } 53 + 49 54 // TODO: This requires packages to be placed before files. At some point this 50 55 // could be relaxed. 51 56 i := 0 ··· 65 70 return []*build.Instance{c.newErrInstance(err)} 66 71 } 67 72 ctx := context.TODO() 68 - if c == nil { 69 - c = &Config{} 70 - } 71 73 newC, err := c.complete() 72 74 if err != nil { 73 75 return []*build.Instance{c.newErrInstance(err)}