Skip to content

Error "field X not present in Y" returned by Subsume when field does exist #3861

@GrahamDennis

Description

@GrahamDennis

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

$ cue version
cue version v0.12.0

go version go1.24.1
      -buildmode exe
       -compiler gc
       -trimpath true
  DefaultGODEBUG asynctimerchan=1,gotestjsonbuildtext=1,gotypesalias=0,httpservecontentkeepheaders=1,multipathtcp=0,randseednop=0,rsa1024min=0,tls3des=1,tlsmlkem=0,x509keypairleaf=0,x509negativeserial=1,x509rsacrt=0,x509usepolicies=0
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
cue.lang.version v0.12.0

Does this issue reproduce with the latest stable release?

Yes

What did you do?

When following the Schema Definition use case example, the error returned can indicate that a field doesn't exist in the target schema instead of correctly indicating that they are not compatible.

In the example below I am determining if #V2 subsumes #v1 and then printing the errors with errors.Print:

#V1: {
    messages: Foo: crc: 32
}


#V2: {
    messages: Foo: crc: 31 | 33
}

the errors displayed are:

field Foo not present in {Foo:{crc:32}}:
    ./schema.cue:2:15
field crc not present in {crc:32}:
    ./schema.cue:2:20
field messages not present in {messages:{Foo:{crc:32}}}:
    ./schema.cue:1:6
missing field "messages"

What did you expect to see?

More useful error messages would be

31 | 33 does not subsume 32:
    ./schema.cue:2:25
    ./schema.cue:7:25
{Foo:{crc:31 | 33}} does not subsume {Foo:{crc:32}}:
    ./schema.cue:2:15
    ./schema.cue:7:15
{crc:31 | 33} does not subsume {crc:32}:
    ./schema.cue:2:20
    ./schema.cue:7:20

What did you see instead?

field Foo not present in {Foo:{crc:32}}:
    ./schema.cue:2:15
field crc not present in {crc:32}:
    ./schema.cue:2:20
field messages not present in {messages:{Foo:{crc:32}}}:
    ./schema.cue:1:6
missing field "messages"

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