Skip to content

Conversation

@jrr6
Copy link
Contributor

@jrr6 jrr6 commented Jun 11, 2025

This PR adds support for throwing named errors with associated error explanations. In particular, it adds elaborators for the syntax defined in #8649, which use the error-explanation infrastructure added in #8651. This includes completions, hovers, and jump-to-definition for error names.

Note that another stage0 rebuild will be required to define explanations using register_error_explanation.

@jrr6 jrr6 requested a review from nomeata June 11, 2025 18:31
@jrr6 jrr6 requested a review from mhuisi as a code owner June 11, 2025 18:31
@jrr6 jrr6 added the changelog-language Language features and metaprograms label Jun 11, 2025
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jun 11, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Jun 11, 2025

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 77fd1ba6b91b0bb439bb5a75b819d1f3588a853f --onto 0a9c24649767dea857a388e5385b7ae94bfd0185. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-11 19:11:42)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 77fd1ba6b91b0bb439bb5a75b819d1f3588a853f --onto 957b904ef9fd11ed9cb49f12fcc9d7b989c01900. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-16 15:24:22)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 77fd1ba6b91b0bb439bb5a75b819d1f3588a853f --onto 3b2990b3816b7e7ec289ad498496a61d18bd85f4. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-17 16:37:21)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 77fd1ba6b91b0bb439bb5a75b819d1f3588a853f --onto e83b7681407043c75f5167c2e4da13e25078a0c0. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-18 15:34:15)

Co-authored-by: Joachim Breitner <[email protected]>
Comment on lines +89 to +90
logErrorAt id m!"There is no explanation associated with the name `{name}`. \
Add an explanation of this error to the `Lean.ErrorExplanations` module."
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this error also suggest how to add an error explanation, or would that be too fragile? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll be adding a README with more detailed instructions to src/Lean/ErrorExplanations/ once I add that module (post-stage0 rebuild).

Copy link
Contributor

@mhuisi mhuisi left a comment

Choose a reason for hiding this comment

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

All of my remaining comments are nitpicks, feel free to merge as you see fit! :-)

Comment on lines +23 to +27
/-- Example -/
register_error_explanation TestDomain.Foo2 {
summary := "Error 2"
sinceVersion := "4.0.0"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I noticed when playing around with this and writing some test error explanation myself was that forgetting the docstring on register_error_explanation results in the following unhelpful error:

unexpected token 'register_error_explanation'; expected command

Copy link
Contributor Author

@jrr6 jrr6 Jun 18, 2025

Choose a reason for hiding this comment

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

Oh, good catch! Improving this will require a syntax change and re-bootstrapping, though, so probably best left to a separate PR.

@jrr6 jrr6 added this pull request to the merge queue Jun 18, 2025
Merged via the queue into leanprover:master with commit e5c6fe1 Jun 18, 2025
15 checks passed
algebraic-dev pushed a commit to algebraic-dev/lean4 that referenced this pull request Jun 18, 2025
…prover#8730)

This PR adds support for throwing named errors with associated error
explanations. In particular, it adds elaborators for the syntax defined
in leanprover#8649, which use the error-explanation infrastructure added in leanprover#8651.
This includes completions, hovers, and jump-to-definition for error
names.

Note that another stage0 rebuild will be required to define explanations
using `register_error_explanation`.

---------

Co-authored-by: Joachim Breitner <[email protected]>
Co-authored-by: Marc Huisinga <[email protected]>
wkrozowski pushed a commit to wkrozowski/lean4 that referenced this pull request Jun 24, 2025
…prover#8730)

This PR adds support for throwing named errors with associated error
explanations. In particular, it adds elaborators for the syntax defined
in leanprover#8649, which use the error-explanation infrastructure added in leanprover#8651.
This includes completions, hovers, and jump-to-definition for error
names.

Note that another stage0 rebuild will be required to define explanations
using `register_error_explanation`.

---------

Co-authored-by: Joachim Breitner <[email protected]>
Co-authored-by: Marc Huisinga <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-language Language features and metaprograms toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants