doc: improve error message for unknown attributes
This PR improves error message for unknown attributes, including labels. Instead of "unknown attribute", the message how instructs the user to define/import their attributes/labels in/from a separate file.
Closes #4011
Mathlib CI status (docs):
- ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the
nightly-with-mathlibbranch. Trygit rebase de5b7f235a71d301bffbb2dbe607ec36dd58cce7 --onto 84b251f7390c20a0a00a221050ab4a6e6c46a191. You can force Mathlib CI using theforce-mathlib-cilabel. (2026-06-29 06:44:33) - ✅ Mathlib branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-05 09:40:30) View Log
- ✅ Mathlib branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-13 06:58:12) View Log
- ❗ Mathlib CI can not be attempted yet, as the
nightly-testing-2026-07-18tag does not exist there yet. We will retry when you push more commits. If you rebase your branch ontonightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using theforce-mathlib-cilabel. (2026-07-18 12:06:14)
Reference manual CI status:
- ❗ Reference manual CI will not be attempted unless your PR branches off the
nightly-with-manualbranch. Trygit rebase de5b7f235a71d301bffbb2dbe607ec36dd58cce7 --onto 84b251f7390c20a0a00a221050ab4a6e6c46a191. You can force reference manual CI using theforce-manual-cilabel. (2026-06-29 06:44:35) - ✅ Reference manual branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-05 08:45:24) View Log
- 🟡 Reference manual branch lean-pr-testing-14213 build against this PR didn't complete normally. (2026-07-05 08:46:32) View Log
- ✅ Reference manual branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-13 06:04:30) View Log
- 🟡 Reference manual branch lean-pr-testing-14213 build against this PR didn't complete normally. (2026-07-13 06:06:25) View Log
- ✅ Reference manual branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-18 12:11:19) View Log
- 🟡 Reference manual branch lean-pr-testing-14213 build against this PR didn't complete normally. (2026-07-18 12:12:33) View Log
That would be best, indeed. However, my understanding of Lean internals is sketchy at best.
According to it, I would need to:
- extend
Lean.Parser.Command.«initialize»to be able to tell if the command is initializing an attribute (orLabelAttribute, specifically) - introduce a new extension similar to
builtin_initialize declRangeExt : MapDeclarationExtension DeclarationRanges, but non-persistent - write to it from the
initializesimilarly to howaddDeclarationRangesForBuiltindoes today. - consult this extension in
elabAttrto see itinitializehas already seen it.
Is this what you had in mind? Please, let me know if you think this is something I could work on, or if this is too complicated for a first-time contributor.
By the way, there's another, simpler way, but it is specific to LabelAttribute, and feels like a hack, tbh. We can inspect the syntax of the attribute in elabAttr. Because LabelAttribute declares its own named syntax, we can tell if the attribute has or has not been declared, look:
I've updated the PR with this PoC.