Skip to content

fix(patterns): use qp for nested pattern error messages#2868

Merged
erights merged 5 commits intomasterfrom
markm-qp-nested-pattern-errors
Jun 26, 2025
Merged

fix(patterns): use qp for nested pattern error messages#2868
erights merged 5 commits intomasterfrom
markm-qp-nested-pattern-errors

Conversation

@erights
Copy link
Copy Markdown
Contributor

@erights erights commented Jun 24, 2025

Closes: #XXXX
Refs: #2799

Description

#2799 added a new q-like quoter named qp, for "quote passable", that renders any value into Justin source text. This was specifically motivated for displaying patterns within error messages in a readable and informative manner.

The @endo/patterns package itself formulates many error messages to explain why a specimen did not match a pattern. Some of these message include quoted forms of nested patterns. But those were still quotes with q, leading @dckc to report still seeing error messages like

Error {
    message: '... - Must match one of ["[match:splitRecord]","[match:splitRecord]"]',
  }

This PR changes the quoting of nested errors to use qp instead, so a [match:splitRecord] might instead render as

`makeTagged("match:splitRecord", [
  {
    assetKind: makeTagged("match:or", [
      "nat",
      "set",
      "copySet",
      "copyBag",
    ]),
    decimalPlaces: makeTagged("match:and", [
      makeTagged("match:gte", -100),
      makeTagged("match:lte", 100),
    ]),
  },
])`

This is more verbose. But error messages are designed to carry the critical clues to help find a bug. For nested patterns, this extra information is worth the verbosity.

Security Considerations

We were already quoting nested patterns with q, unredacting them, under the assumption that specimens may carry secrets worth protecting from callers, but patterns typically do not. Switching these from q to qp is consistent with that assumption, but actually exposes info that q happened not to expose. When unredacting happened not to expose secrets it said were ok to expose, it is easy for developers not to notice the secrets that could have been shown but weren't. After this PR, these unredacted secrets will be exposed to callers.

Scaling Considerations

Where q is lazy, qp is eager, rendering its argument up front into Justin even if the containing error is never created or thrown. Thus, we must take care to only use qp when we're already committed to creating and throwing the error. I believe all such changes in this PR do so, and so do not add overhead to the happy path.

Documentation Considerations

I don't know what documentation we provide explaining the interpretation of error messages. If we have any explain pattern match error messages, this PR might need us to change those explanations.

Testing Considerations

Using qp to formulate the error messages definitely makes it more awkward to test is the error message is as expected. You can see this in the tests this PR needed to change. Fortunately, as shown in these error message tests, you can use ${q(qp(...))} to formulate the golden in the test.

Compatibility Considerations

Because this PR changes the error messages, as pointed out above, golden tests of error message text may no longer match, causing old working tests to start failing. However, this is not technically a compat break, because we take the stance that the content of error messages is not normative, so the error messages can become more informative over time with a version bump. Thus, I use : rather than ! to recommend that this PR not cause a version bump. (See #2868 (review) below)

Upgrade Considerations

None.

@erights erights changed the title fix(patterns)! use qp for nested pattern error messages fix(patterns)! use qp for nested pattern error messages Jun 24, 2025
@erights erights self-assigned this Jun 24, 2025
@erights erights requested review from dckc and kriskowal June 24, 2025 05:01
@erights erights force-pushed the markm-qp-nested-pattern-errors branch from 7941bca to e0c8870 Compare June 24, 2025 05:02
@erights erights marked this pull request as ready for review June 24, 2025 05:33
Copy link
Copy Markdown
Contributor

@dckc dckc left a comment

Choose a reason for hiding this comment

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

works for me, but I defer to more active maintainers (@kriskowal ) to approve

for golden tests, I find ava snapshots pretty handy

Copy link
Copy Markdown
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

Please remove the ! from the commit message and PR description. If this is going to cause practical consequences for Agoric CI, please add a commit to endo-integration-master to reconcile or relax the overconstrained tests instead. You will likely need to verify this one with an endo-branch pinned in an Agoric SDK PR to validate that, but I prefer that over the eval twins we’ll inevitably have to iron out if we ramp the major version for error message changes, which I don’t consider part of our contract.

Also, please take care to remove the checklist from the end of the PR description so it doesn’t get preserved in the merge commit message.

@erights erights changed the title fix(patterns)! use qp for nested pattern error messages fix(patterns): use qp for nested pattern error messages Jun 25, 2025
@erights erights force-pushed the markm-qp-nested-pattern-errors branch from 82efbff to 43affe0 Compare June 25, 2025 02:45
@erights
Copy link
Copy Markdown
Contributor Author

erights commented Jun 25, 2025

for golden tests, I find ava snapshots pretty handy

Thanks. I will keep that in mind next time I'm adding or maintaining tests with golden tests. Thanks!

But it doesn't sound like you're requesting that shift in this PR. I agree that it isn't needed in this PR, so not doing it.

@erights
Copy link
Copy Markdown
Contributor Author

erights commented Jun 25, 2025

Please remove the ! from the commit message and PR description.

Done

If this is going to cause practical consequences for Agoric CI, please add a commit to endo-integration-master

What is endo-integration-master? Where do I find it? (I looked in the places I expected and did not find it.)

to reconcile or relax the overconstrained tests instead. You will likely need to verify this one with an endo-branch pinned in an Agoric SDK PR to validate that,

Aside from "What is endo-integration-master?", I like that plan.

but I prefer that over the eval twins we’ll inevitably have to iron out if we ramp the major version for error message changes, which I don’t consider part of our contract.

Agreed.

Also, please take care to remove the checklist from the end of the PR description so it doesn’t get preserved in the merge commit message.

Done

@erights erights requested a review from kriskowal June 25, 2025 03:26
@erights
Copy link
Copy Markdown
Contributor Author

erights commented Jun 26, 2025

If this is going to cause practical consequences for Agoric CI, please add a commit to endo-integration-master

In accord with our conversation, both Agoric/agoric-sdk#7937 and Agoric/agoric-sdk#9201 are rebased on agoric-sdk master. The only difference between them is the #endo-branch. Both in CI now. I decided not to cherry pick anything, since we agreed that if they have the same CI errors and the errors are unrelated to this PR, then we're clear. Otherwise, I'll create an agoric-sdk PR that fixes the relevant differences revealed by that experiment.

Watching.

@erights
Copy link
Copy Markdown
Contributor Author

erights commented Jun 26, 2025

WOOHOO!

Both Agoric/agoric-sdk#7937 and Agoric/agoric-sdk#9201 are green in CI, even though I'm just using agoric-sdk master without cherry picking your sync repairs.

@erights erights merged commit ec4e4c0 into master Jun 26, 2025
16 checks passed
@erights erights deleted the markm-qp-nested-pattern-errors branch June 26, 2025 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants