HashQL Diagnostic Writing
Provides HASH-specific patterns for writing high-quality diagnostics using the hashql-diagnostics crate, ensuring messages are helpful, actionable, and follow consistent style conventions.
Core Principles
Diagnostics should be helpful, not just correct:
✅ DO:
- Start messages with lowercase
- Use backticks for code elements:
expected `bool`, found `String`
- Make messages actionable and specific
- Use "invalid" not "illegal"
- Keep help messages as imperatives: "add type annotations"
❌ DON'T:
- End messages with punctuation (unless multi-sentence)
- Use apologetic language ("sorry", "unfortunately")
- Write vague messages ("something went wrong")
- Capitalize message starts (unless code identifier)
Quick Reference
Creating a Diagnostic
use hashql_diagnostics::{Diagnostic, Label, Message, Severity};
let mut diagnostic = Diagnostic::new(category, Severity::Error)
.primary(Label::new(span, "expected `bool`, found `String`"));
diagnostic.add_label(Label::new(other_span, "expected because of this"));
diagnostic.add_message(Message::help("try using a comparison"));
Severity Levels
| Severity |
When to Use |
Bug |
Internal compiler error |
Fatal |
Unrecoverable error |
Error |
Must be fixed to compile |
Warning |
Suspicious code to review |
Note |
Informational context |
Message Style
// ✅ Good
"cannot find variable `count` in this scope"
"expected `;` after expression"
// ❌ Bad
"Error: Variable not found." // capitalized, punctuation
"Sorry, there's a type mismatch" // apologetic
Adding Suggestions
use hashql_diagnostics::{Message, Patch, Suggestions};
let suggestion = Suggestions::patch(Patch::new(span, "corrected_code"));
diagnostic.add_message(
Message::help("fix the typo").with_suggestions(suggestion)
);
References
- Comprehensive guidelines - Complete message style guide, span selection, category design, label usage, help vs note, suggestion quality, review checklist
- HashQL testing skill - For compiletest coverage
1---2name: writing-hashql-diagnostics3description: HashQL diagnostic writing patterns using hashql-diagnostics crate. Use when creating error messages, warnings, Labels, Messages, Severity levels, Patches, Suggestions, or improving diagnostic quality in HashQL code.4license: AGPL-3.05---67# HashQL Diagnostic Writing89Provides HASH-specific patterns for writing high-quality diagnostics using the `hashql-diagnostics` crate, ensuring messages are helpful, actionable, and follow consistent style conventions.1011## Core Principles1213**Diagnostics should be helpful, not just correct:**1415✅ **DO:**1617- Start messages with lowercase18- Use backticks for code elements: `` expected `bool`, found `String` ``19- Make messages actionable and specific20- Use "invalid" not "illegal"21- Keep help messages as imperatives: "add type annotations"2223❌ **DON'T:**2425- End messages with punctuation (unless multi-sentence)26- Use apologetic language ("sorry", "unfortunately")27- Write vague messages ("something went wrong")28- Capitalize message starts (unless code identifier)2930## Quick Reference3132### Creating a Diagnostic3334```rust35use hashql_diagnostics::{Diagnostic, Label, Message, Severity};3637let mut diagnostic = Diagnostic::new(category, Severity::Error)38 .primary(Label::new(span, "expected `bool`, found `String`"));3940diagnostic.add_label(Label::new(other_span, "expected because of this"));41diagnostic.add_message(Message::help("try using a comparison"));42```4344### Severity Levels4546| Severity | When to Use |47| --------- | ------------------------- |48| `Bug` | Internal compiler error |49| `Fatal` | Unrecoverable error |50| `Error` | Must be fixed to compile |51| `Warning` | Suspicious code to review |52| `Note` | Informational context |5354### Message Style5556```rust57// ✅ Good58"cannot find variable `count` in this scope"59"expected `;` after expression"6061// ❌ Bad62"Error: Variable not found." // capitalized, punctuation63"Sorry, there's a type mismatch" // apologetic64```6566### Adding Suggestions6768```rust69use hashql_diagnostics::{Message, Patch, Suggestions};7071let suggestion = Suggestions::patch(Patch::new(span, "corrected_code"));72diagnostic.add_message(73 Message::help("fix the typo").with_suggestions(suggestion)74);75```7677## References7879- [Comprehensive guidelines](references/guidelines.md) - Complete message style guide, span selection, category design, label usage, help vs note, suggestion quality, review checklist80- [HashQL testing skill](../testing-hashql/SKILL.md) - For compiletest coverage