cue
cue copied to clipboard
evaluator: required field constraint error dropped for non-top-level hidden fields
What version of CUE are you using (cue version)?
$ cue version
cue version v0.0.0-20230824070308-49728f709d7a
go version go1.20.6
-buildmode exe
-compiler gc
CGO_ENABLED 1
GOARCH arm64
GOOS linux
vcs git
vcs.revision 49728f709d7a171479c352a8fffe9828e70a896c
vcs.time 2023-08-24T07:03:08Z
vcs.modified false
Does this issue reproduce with the latest release?
Yes
What did you do?
! exec cue export x.cue
cmp stderr stderr.golden
-- x.cue --
_a: {
a!: string
}
_b!: string
c: {
_c!: string
}
d: {
_d: {
d!: string
}
}
-- stderr.golden --
_a.a: field is required but not present:
./x.cue:2:2
_b: field is required but not present:
./x.cue:4:1
c._c: field is required but not present:
./x.cue:6:2
d._d.d: field is required but not present:
./x.cue:10:3
What did you expect to see?
The test to pass.
What did you see instead?
> ! exec cue export x.cue
[stderr]
_b: field is required but not present:
./x.cue:4:1
c._c: field is required but not present:
./x.cue:6:2
[exit status 1]
> cmp stderr stderr.golden
--- stderr
+++ stderr.golden
@@ -1,4 +1,8 @@
+_a.a: field is required but not present:
+ ./x.cue:2:2
_b: field is required but not present:
./x.cue:4:1
c._c: field is required but not present:
./x.cue:6:2
+d._d.d: field is required but not present:
+ ./x.cue:10:3
FAIL: /tmp/testscript4283636604/repro.txtar/script.txtar:2: stderr and stderr.golden differ
Still seems to be an issue as of v0.13.0 with evalv3.
My current understanding is that required fields are a constraint applied to the exported data, so any non-exported values such as definitions or hidden fields having missing required fields should not result in an error.
With that logic, I actually think that the current behavior is workign as intended. _a and d._d are both hidden, so any required fields underneath them are not part of the export structs, and are not checked. However, the top-level struct and c are being exported, so _b and c._c are both checked as required fields.
The spec says:
Implementations may error upon encountering a required field constraint when manifesting CUE as data.
So that's how I understand cue export "manifests CUE as data", as it omits anything below hidden fields.
Labelling as "WorkingAsIntended" even though I'm not 100% sure about that suspicion. Perhaps @cuematthew can help clarify.
@cuematthew has no clarification to offer. But @mvdan, your
any non-exported values such as definitions or hidden fields having missing required fields should not result in an error
makes sense to me, and is consistent with the errors that are produced. But I think there is room for debate as to the range of error reporting users may wish to see here.