cue icon indicating copy to clipboard operation
cue copied to clipboard

cmd/cue: misleading error report

Open rogpeppe opened this issue 4 years ago • 0 comments

commit 9217c4d0b6f86ba942e66ea6049e1517e43a7fdf

I've left some of the original structure here to give a flavour of the kind of thing I was dealing with. The example this derived from consisted over 60k lines of CUE.

I spent a couple of hours to trying to work out what the conflict was here. The problem is that for some reason, the first error doesn't seem like it should be a conflict at all - it says that the properties field isn't allowed inside cloud.components.schemas.OnboardingResponse.properties.bucket, but it seems clear that that path does allow a properties field (by virtue of allowing commonschemas.Bucket which has a properties field).

The actual error is highlighted by the second message, but that breaks the usual flow of fixing the first error that we see, then moving on. In the original, there were many errors and the retentionRules one was 6th in the list.

exec cue vet -c

-- openapi.cue --
package contracts

new: cloud: components: schemas: OnboardingResponse: cloudschemas.OnboardingResponse

cloudschemas: OnboardingResponse: properties: bucket: *commonschemas.Bucket.#Ref | commonschemas.Bucket

old: cloud: components: schemas: OnboardingResponse: properties: bucket: properties: retentionRules: {
	items: type: "object"
}

commonschemas: Bucket: {
	#Ref: $ref:                 "x"
	properties: retentionRules: commonschemas.RetentionRules
}

commonschemas: RetentionRules: {
	#Ref: $ref:  "y"
	items: $ref: "foo"
}

#New: new
#Old: old

#Both: #Old & #New

I see this output:

#Both.cloud.components.schemas.OnboardingResponse.properties.bucket: 2 errors in empty disjunction:
#Both.cloud.components.schemas.OnboardingResponse.properties.bucket: field not allowed: properties:
    ./openapi.cue:3:54
    ./openapi.cue:5:56
    ./openapi.cue:7:74
    ./openapi.cue:12:8
    ./openapi.cue:21:7
    ./openapi.cue:22:7
    ./openapi.cue:24:8
    ./openapi.cue:24:15
#Both.cloud.components.schemas.OnboardingResponse.properties.bucket.properties.retentionRules.items: field not allowed: type:
    ./openapi.cue:3:54
    ./openapi.cue:5:84
    ./openapi.cue:8:9
    ./openapi.cue:13:30
    ./openapi.cue:18:9
    ./openapi.cue:21:7
    ./openapi.cue:22:7
    ./openapi.cue:24:8
    ./openapi.cue:24:15

rogpeppe avatar Nov 22 '21 09:11 rogpeppe