Skip to content

Conversation

GrahamDennis
Copy link

Previously when Subsume determined that a field did not subsume a previous field, the error returned was:

field x not present in <value>

which is simply not true. Now a more useful error is returned in this scenario:

31 | 33 does not subsume 32:
    ./schema.cue:2:25
    ./schema.cue:7:25

Resolves: #3861

@GrahamDennis GrahamDennis requested a review from cueckoo as a code owner March 29, 2025 00:20
@mvdan
Copy link
Member

mvdan commented Mar 29, 2025

Thanks for the patch. Could you add a test? Interestingly, we don't seem to have no tests for "field ... not present in ...". I would imagine this test would go somewhere under cue/testdata. Best if you add the test in a first commit, then the second commit can update the expected output and show the improvement in behavior.

Signed-off-by: Graham Dennis <graham.dennis@gmail.com>
@GrahamDennis GrahamDennis force-pushed the gdennis/improve-subsumption-error branch from 023fd6d to 0acd636 Compare March 29, 2025 05:00
@GrahamDennis
Copy link
Author

GrahamDennis commented Mar 29, 2025

Thanks for the patch. Could you add a test? Interestingly, we don't seem to have no tests for "field ... not present in ...". I would imagine this test would go somewhere under cue/testdata. Best if you add the test in a first commit, then the second commit can update the expected output and show the improvement in behavior.

Thanks for the feedback. I've done this now.

The first commit contains just the new tests and contains some examples that I think have incorrect error messages:

-- out/TestValues/407/{foo:_1}_⊑_{foo?:_1} --
Errors:
field foo not present in {foo?:1}:
    value:1:17
missing field "foo"

Result:
false

After the second commit, the updated error message is:

-- out/TestValues/407/{foo:_1}_⊑_{foo?:_1} --
Errors:
1 does not subsume 1:
    value:1:10
    value:1:24
1 does not subsume 1?:
    value:1:10
    value:1:24

Result:
false

edit: I fixed a bug in my change with the error messages generated by the v3 evaluator vs the v2 evaluator.

@GrahamDennis GrahamDennis force-pushed the gdennis/improve-subsumption-error branch from 3262af0 to 63e5fcd Compare March 29, 2025 05:15
Previously when Subsume determined that a field did not subsume
a previous field, the error returned was:

```
field x not present in <value>
```

which is simply not true. Now a more useful error is returned in this
scenario:

```
31 | 33 does not subsume 32:
    ./schema.cue:2:25
    ./schema.cue:7:25
```

Resolves: cue-lang#3861

Signed-off-by: Graham Dennis <graham.dennis@gmail.com>
@GrahamDennis GrahamDennis force-pushed the gdennis/improve-subsumption-error branch from 63e5fcd to d50ef8c Compare March 29, 2025 05:38
s.missing = f
s.gt = a
s.lt = y
if b == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I have removed this and also set the s.missing et al fields inside the block above.

s.missing = f
s.gt = a
s.lt = y
if b == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unclear how this condition can ever be true: if b == nil, b will be set to a non-nil value in the block above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I have removed this and also set the s.missing et al fields inside the block above.

@@ -0,0 +1,4837 @@
-- out/TestValues/0/__⊑__/v2 --
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any test inputs here. Am I missing something?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is driven by the existing test cases in https://github.com/cue-lang/cue/pull/3862/files#diff-5c570d819733910b5664134701d7cb95c9efbf2261b72b32b3ff5339ef18bb27L52-R77.
What I wanted to do was re-use all of those test cases and then use the txtar tooling for rendering the error messages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically want to keep the tests together. So either put input an output in txtar, or do everything in a table.

Also, we prefer not to change the general design of test. It is a lot of code to review! Finally, we want to separate out semantic from structural changes. So if we want to change the generic test structure, this should be a separate CL.

Signed-off-by: Graham Dennis <graham.dennis@gmail.com>
@GrahamDennis GrahamDennis force-pushed the gdennis/improve-subsumption-error branch from 26551a3 to d27ca9c Compare April 12, 2025 04:49
s.lt = y
s.lt = b

s.errf("%v%s does not subsume %v%s", a, a.ArcType.Suffix(), b, b.ArcType.Suffix())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been modified to improve the error for situations like: {foo:_1}_⊑_{foo?:_1}. Currently the error is:

1 does not subsume 1

But there will now be a new error of

1 does not subsume 1?

This may be considered an abuse of syntax, but it's a starting point for discussion.

@@ -0,0 +1,4837 @@
-- out/TestValues/0/__⊑__/v2 --
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is driven by the existing test cases in https://github.com/cue-lang/cue/pull/3862/files#diff-5c570d819733910b5664134701d7cb95c9efbf2261b72b32b3ff5339ef18bb27L52-R77.
What I wanted to do was re-use all of those test cases and then use the txtar tooling for rendering the error messages.

s.missing = f
s.gt = a
s.lt = y
if b == nil {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I have removed this and also set the s.missing et al fields inside the block above.

s.missing = f
s.gt = a
s.lt = y
if b == nil {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I have removed this and also set the s.missing et al fields inside the block above.

@GrahamDennis
Copy link
Author

Ping on this PR?

@mvdan
Copy link
Member

mvdan commented May 14, 2025

We haven't forgotten about your PRs; we're just in a bit of a crunch for the v0.13 release with the new evaluator :) Please bear with us, and thank you for your patience!

@GrahamDennis
Copy link
Author

ping @mvdan ? Any update here now that 0.13 is out?

@GrahamDennis
Copy link
Author

ping @mvdan / @mpvl ?

@mvdan
Copy link
Member

mvdan commented Jul 16, 2025

Thanks; we haven't forgotten about this. Please understand that we have a number of competing priorities at the moment, and a small team.

Copy link
Member

@mpvl mpvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your updates and pardon the delay.

Firstly, this is quite a complex change. For anything but trivial changes we typically require moving over to Gerrit, for several reasons:

  1. all reviews documented in a single place,
  2. code review capabilities of GH are rather poor (for instance no fine-grained colored diffing), which makes it really hard to review,
  3. allow commenting on commit messages (for instance, headers do not follow our pattern).

I made some comments, but I suggest moving over to Gerrit henceforth.

@@ -0,0 +1,4837 @@
-- out/TestValues/0/__⊑__/v2 --
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically want to keep the tests together. So either put input an output in txtar, or do everything in a table.

Also, we prefer not to change the general design of test. It is a lot of code to review! Finally, we want to separate out semantic from structural changes. So if we want to change the generic test structure, this should be a separate CL.

s.errf("missing field %q", s.missing.SelectorString(c))
} else if b, ok := unifyValue(c, s.gt, s.lt).(*adt.Bottom); !ok {
s.errf("value not an instance")
s.errf("field %q not present in %v", s.missing.SelectorString(c), s.lt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit contains rephrasing of error messages, as well as logic changes. This makes it non-trivial to see which tests change because of what. These should be separated out in different CLs.

@mpvl
Copy link
Member

mpvl commented Aug 5, 2025

I've updated the testing setup for TestValues. It now tests for the particular error message. You can run

CUE_UPDATE=1 go test ./internal/core/subsume  

To update the generated error messages.

The reviews for this are still pending, though: https://review.gerrithub.io/c/cue-lang/cue/+/1219851/1

@mvdan
Copy link
Member

mvdan commented Sep 1, 2025

Friendly nudge @GrahamDennis, not sure if you saw Marcel's replies above. You can see https://github.com/cue-lang/cue/blob/master/CONTRIBUTING.md in terms of sending patches on Gerrit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error "field X not present in Y" returned by Subsume when field does exist
3 participants