Skip to content

Cue error deduplication does not preserve order #3859

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

Open
GrahamDennis opened this issue Mar 28, 2025 · 0 comments · May be fixed by #3860
Open

Cue error deduplication does not preserve order #3859

GrahamDennis opened this issue Mar 28, 2025 · 0 comments · May be fixed by #3860
Labels
NeedsInvestigation Triage Requires triage/attention

Comments

@GrahamDennis
Copy link

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, multiple errors can be returned by v3.Subsume(v2). When printing these errors using errors.Print, these errors are displayed in a non-intuitive order instead of inner-to-outer or outer-to-inner because these errors are being sorted as part of a deduplication process.

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?

A more useful ordering of the errors would be:

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

which is the order of the underlying array before errors.RemoveMultiples() is called.

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"

There is a separate issue where the error messages above are incorrect (the field isn't missing, it's just that crc: 31 | 33 does not subsume crc: 32. I will file a separate issue for that.

@GrahamDennis GrahamDennis added NeedsInvestigation Triage Requires triage/attention labels Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Triage Requires triage/attention
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant