handling-rust-errors
/handling-rust-errors
Opisuje wzorce obsługi błędów HASH z użyciem crate error-stack w Rust: typy Result i Report, własne błędy, change_context, attach, trait Error i dokumentowanie warunków błędów.
- Autor
- hashintel ↗
- Repozytorium
- hash ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 24.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 4
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 24.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Opisuje wzorce obsługi błędów HASH z użyciem crate error-stack w Rust: typy Result i Report, własne błędy, change_context, attach, trait Error i dokumentowanie warunków błędów.
Oryginalny opis (EN)
HASH error handling patterns using error-stack crate. Use when working with Result types, Report types, defining custom errors, propagating errors with change_context, adding context with attach, implementing Error trait, or documenting error conditions in Rust code.
Jak działa
- Core Principles
- HashQL Compiler Exception
- Quick Start Guide
- Common Quick Patterns
- References
Podgląd SKILL.md
---
name: handling-rust-errors
description: HASH error handling patterns using error-stack crate. Use when working with Result types, Report types, defining custom errors, propagating errors with change_context, adding context with attach, implementing Error trait, or documenting error conditions in Rust code.
license: AGPL-3.0
---
# Rust Error-Stack Patterns
HASH-specific error handling patterns using the `error-stack` crate for consistent, debuggable error handling across the Rust codebase.
## Core Principles
**HASH uses `error-stack` exclusively for error handling:**
✅ **DO:**
- Use `Report<MyError>` for all error types
- Use concrete error types: `Report<MyError>`
- Import `Error` from `core::error::` (not `std::error::`)
- Import `ResultExt as _` for trait methods
❌ **DON'T:**
- Use `anyhow` or `eyre` crates
- Use `Box<dyn Error>` (except in tests/prototyping)
- Use `Report<Box<dyn Error>>`
- Use `thiserror` (use `derive_more` instead)
## HashQL Compiler Exception
**HashQL compiler code uses a different error handling approach.**
Code in `libs/@local/hashql/*` uses the `hashql-diagnostics` crate instead of `error-stack`. This is because compiler errors require rich formatting capabilities:
- Source spans pointing to exact code locations
- Multiple labeled regions within the same diagnostic
- Fix suggestions with replacement text
- Severity levels (error, warning, hint)
**Which approach to use:**
| Location | Error Handling |
| -------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `libs/@local/hashql/*` (compiler code) | Use `hashql-diagnostics` → See [writing-hashql-diagnostics](../writing-hashql-diagnostics/SKILL.md) skill |
| Everywhere else | Use `error-stack` patterns from this skill |
Traditional `error-stack` patterns still apply for HashQL infrastructure code (CLI, file I/O, configuration) that doesn't involve compiler diagnostics.
## Quick Start Guide
Choose the reference that matches your current task:
### Defining Errors
**Use when:** Creating new error types or error enums
- Define error types with `derive_more`
- Error enum patterns and variants
- Implement the `Error` trait
- Error type hierarchies
### Propagating Errors
**Use when:** Handling `Result` types, using `?` operator
- Convert errors with `.change_context()` and `.change_context_with()`
- Add context with `.attach()` and `.attach_with()`
- Error conversion patterns
### Documenting Errors
**Use when:** Writing doc comments for fallible functions
- `# Errors` section format
- Link error variants
- Document runtime errors
- Test error conditions
## Common Quick Patterns
### Creating an Error
```rust
use error_stack::Report;
return Err(Report::new(MyError::NotFound))
.attach(format!("ID: {}", id));
```
### Propagating with Context
```rust
use error_stack::ResultExt as _;
some_result
.change_context(MyError::OperationFailed)
.attach("Additional context")?;
```
### Lazy Context (for expensive operations)
```rust
use error_stack::ResultExt as _;
expensive_operation()
.change_context(MyError::OperationFailed)
.attach_with(|| format!("Debug info: {:?}", expensive_computation()))?;
```
## References
- [Defining Errors](references/defining-errors.md) - Creating new error types or error enums
- [Propagating Errors](references/propagating-errors.md) - Handling `Result` types, using `?` operator
- [Documenting Errors](references/documenting-errors.md) - Writing doc comments for fallible functions
Pliki w paczce (4)
- SKILL.md 4 KB
- references/defining-errors.md 6 KB
- references/documenting-errors.md 8 KB
- references/propagating-errors.md 7 KB
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · hashintel/hash | 100 | MIT |
| zjunlp/skills | 100 | MIT |
Migawka bazy z 28.10.2026 · wersja paczki 527c76afe5c6 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 95rust-error-handling
Dobiera strategię obsługi błędów w Ruście: Result, Option, panic, anyhow kontra thiserror oraz własne typy błędów. - 95rust-error-handling
Opisuje obsługę błędów w Rust z Result, Option, własnymi typami błędów, thiserror i anyhow. - 95rust-error-handling
Wyjaśnia obsługę błędów w Ruście: kiedy Result, Option albo panic, propagację przez ? i projektowanie typów błędów. - 100error-handling
Wdraża wzorce obsługi błędów w Go: opakowywanie błędów, błędy sentinel, własne typy błędów i konwencje propagacji. - 95go-error-handling
Pomaga obsługiwać błędy w aplikacjach Go: opakowywanie błędów, błędy sentinel i własne typy błędów. - 100go-error-handling
Podaje wzorce obsługi błędów w Go: opakowywanie, błędy sentinel, własne typy błędów i pakiet errors, oparte na Effective Go i Go Code Review Comments.