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

pkg/list: UniqueItems' error message when only failing to validate a list of structs is unhelpful #3650

Closed
jpluscplusm opened this issue Jan 3, 2025 · 1 comment
Labels
NeedsInvestigation Triage Requires triage/attention

Comments

@jpluscplusm
Copy link
Collaborator

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

$ cue version
cue version v0.12.0-alpha.1.0.20250103115825-74a0c9d01e05

go version go1.23.0
      -buildmode exe
       -compiler gc
  DefaultGODEBUG asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
cue.lang.version v0.12.0

Does this issue reproduce with the latest stable release?

No; this is a change since v0.11.1 (possibly https://cuelang.org/cl/1204378).

What did you do?

(Whilst re-writing https://cuelang.org/docs/howto/list-no-duplicates/ as part of https://cuelang.org/cl/1206577, I noticed the changes to list.UniqueItems made in https://cuelang.org/cl/1204378. This prompted me to test the rewritten page against the tip of cmd/cue, during which discovery I noticed the following regression in error message clarity.)

! exec cue vet simple.cue
cmp stderr err.simple

! exec cue vet struct.cue
cmp stderr err.struct

! exec cue vet both.cue
cmp stderr err.both

-- simple.cue --
import "list"

a: list.UniqueItems & [
	0, 1, 2, 0,
]
-- struct.cue --
import "list"

b: list.UniqueItems & [
	{foo: 1},
	{foo: 1},
]
-- both.cue --
import "list"

a: list.UniqueItems & [
	0, 1, 2, 0,
]
b: list.UniqueItems & [
	{foo: 1},
	{foo: 1},
]
-- err.simple --
a: invalid value [0,1,2,0] (does not satisfy list.UniqueItems): equal value (0) at position 0 and 3:
    ./simple.cue:3:4
-- err.struct --
b: invalid value [{foo:1},{foo:1}] (does not satisfy list.UniqueItems):
    ./struct.cue:3:4
-- err.both --
a: invalid value [0,1,2,0] (does not satisfy list.UniqueItems): equal value (0) at position 0 and 3:
    ./both.cue:3:4

What did you expect to see?

A passing test; or at least an error message that matches the amount of information provided by cue vet v0.11.1 (which is the command that generated the repro's contents of err.struct)

What did you see instead?

$ testscript -continue list.uniqueItems.obscuresValidationErrorMessages.txtar
> ! exec cue vet simple.cue
[stderr]
a: invalid value [0,1,2,0] (does not satisfy list.UniqueItems): equal value (0) at position 0 and 3:
    ./simple.cue:3:4
[exit status 1]
> cmp stderr err.simple
> ! exec cue vet struct.cue
[stderr]
some instances are incomplete; use the -c flag to show errors or suppress this message
[exit status 1]
> cmp stderr err.struct
diff stderr err.struct
--- stderr
+++ err.struct
@@ -1,1 +1,2 @@
-some instances are incomplete; use the -c flag to show errors or suppress this message
+b: invalid value [{foo:1},{foo:1}] (does not satisfy list.UniqueItems):
+    ./struct.cue:3:4

FAIL: /tmp/testscript4137642471/list.uniqueItems.obscuresValidationErrorMessages.txtar/script.txtar:5: stderr and err.struct differ
> ! exec cue vet both.cue
[stderr]
a: invalid value [0,1,2,0] (does not satisfy list.UniqueItems): equal value (0) at position 0 and 3:
    ./both.cue:3:4
[exit status 1]
> cmp stderr err.both
@jpluscplusm jpluscplusm added NeedsInvestigation Triage Requires triage/attention labels Jan 3, 2025
@jpluscplusm
Copy link
Collaborator Author

A discussion with @myitcv has suggested that this is a case where the cue vet tri-state of -c, -c=true, and -c=false has confused a user (me!). cf. #2120.

Recent fixes to list.UniqueItems mean that, given cue vet's current behaviour, it's correct to have to use cue vet -c to expose the underlying error in this issue's repro's struct.cue.

The behaviour where only one error is shown when validating both.cue has been added as a test case to #1319 (comment)

@jpluscplusm jpluscplusm changed the title list/UniqueItems: error message when only failing to validate a list of structs is unhelpful pkg/list: UniqueItems' error message when only failing to validate a list of structs is unhelpful Jan 3, 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

No branches or pull requests

1 participant