Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eval: error message for disallowed field doesn't mention the disallowed field #3607

Open
rogpeppe opened this issue Dec 2, 2024 · 0 comments
Labels
NeedsFix roadmap/errors Related to improving error messages.

Comments

@rogpeppe
Copy link
Member

rogpeppe commented Dec 2, 2024

What version of CUE are you using (cue version)?

$ cue version
v0.11.0

Does this issue reproduce with the latest stable release?

Yes.

What did you do?

! exec cue vet x.cue
stdout 'description: field not allowed'
-- x.cue --

data: {
	type: "object"
	properties: grandparentAuthor: {
		type:        "ref"
		ref:         "something"
		description: "When parent is a reply to another post, this is the author of that post."
	}
} & #LexType

#LexType: #LexArray | #LexObject | #LexRef

#LexObject: {
	type!:        "object"
	description?: string
	properties!: [string]: #LexType
}

#LexRef: string | {
	type!: "ref"
	ref!:  string
}

#LexArray: {
	type!: "array"
}

What did you expect to see?

A passing test. The error is caused by the fact that #LexRef doesn't allow the field "description" that's present in the data, but the error message doesn't mention anything about that as a possible cause.

What did you see instead?

> ! exec cue vet x.cue
[stderr]
data: 3 errors in empty disjunction:
data: conflicting values string and {type:"object",properties:{grandparentAuthor:{type:"ref",ref:"something",description:"When parent is a reply to another post, this is the author of that post."}}} (mismatched types string and struct):
    ./x.cue:2:7
    ./x.cue:19:10
data.type: conflicting values "array" and "object":
    ./x.cue:3:8
    ./x.cue:9:5
    ./x.cue:11:11
    ./x.cue:25:9
data.type: conflicting values "ref" and "object":
    ./x.cue:3:8
    ./x.cue:9:5
    ./x.cue:11:36
    ./x.cue:20:9
[exit status 1]
> stdout 'description: field not allowed'
FAIL: /tmp/z.txtar:2: no match for `description: field not allowed` found in stdout

ISTM that a much better job could be done by detecting the type discriminator field and including only errors for the arm of the disjunction with the corresponding field. But even so, the error should at least mention the fact that description isn't allowed by #LexRef.

@rogpeppe rogpeppe added NeedsFix roadmap/errors Related to improving error messages. labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix roadmap/errors Related to improving error messages.
Projects
None yet
Development

No branches or pull requests

1 participant