Skip to content

eval: improve error message eagerness around required fields #3845

@myitcv

Description

@myitcv

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

$ cue version
cue version v0.13.0-alpha.1.0.20250322080417-cfbeb48088c9

go version go1.24.0
      -buildmode exe
       -compiler gc
  DefaultGODEBUG gotestjsonbuildtext=1,multipathtcp=0,randseednop=0,rsa1024min=0,tlsmlkem=0,x509rsacrt=0,x509usepolicies=0
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
         GOARM64 v8.0
             vcs git
    vcs.revision cfbeb48088c9674480496969ad85a93602e9778c
        vcs.time 2025-03-22T08:04:17Z
    vcs.modified false
cue.lang.version v0.13.0

Does this issue reproduce with the latest release?

Yes

What did you do?

# use evalv3 - soon to be the default
env CUE_EXPERIMENT=evalv3=1

# cars
! exec cue vet -c cars.yaml x.cue
stderr 'cars\.0\.extra: field not allowed'
stderr 'cars\.0\.year: field is required but not present'

-- cars.yaml --
cars:
  - type: "car"
    name: "Toyota"
    extra: "extra"
-- x.cue --
#Car: {
	type!: "car"
	name!: string
	year!: string
}

cars?: [...#Car]

What did you expect to see?

Passing test... perhaps.

What did you see instead?

Note the use of testscript -continue:

# use evalv3 - soon to be the default (0.000s)
# cars (0.026s)
> ! exec cue vet -c cars.yaml x.cue
[stderr]
cars.0.extra: field not allowed:
    ./cars.yaml:4:5
[exit status 1]
> stderr 'cars\.0\.extra: field not allowed'
> stderr 'cars\.0\.year: field is required but not present'
FAIL: repro.txtar:7: no match for `cars\.0\.year: field is required but not present` found in stderr

In this example we don't see the error message about this missing year field not being present. Is it possible, given that we are running in vet -c mode, to eagerly show this message? Yes, it's conceivable that other fields not being in error could lead to the field being contributed (i.e. via a comprehension) but it seems more useful to show the error message given the error state.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions