# sipha-error
[](https://opensource.org/licenses/MIT)
[](https://github.com/NyalephTheCat/sipha)
[](https://crates.io/crates/sipha-error)
[](https://docs.rs/sipha-error)
Error handling and diagnostics for sipha parsers.
## Overview
`sipha-error` provides comprehensive error handling and diagnostic capabilities for sipha parsers:
- **ParseError**: Enum with all parse error variants
- **Expected**: Type for describing expected tokens
- **ErrorContext**: Context tracking for error reporting
- **Diagnostic**: Rich diagnostic types with miette integration (optional)
## Features
- `default`: Includes `diagnostics` feature
- `diagnostics`: Enables rich error diagnostics with miette integration
- `color`: Adds color support for error output (requires `diagnostics`)
## Quick Start
Add `sipha-error` to your `Cargo.toml`:
```toml
[dependencies]
sipha-error = "0.1.1"
```
With diagnostics:
```toml
[dependencies]
sipha-error = { version = "0.1.1", features = ["diagnostics", "color"] }
```
## Example
```rust
use sipha_error::{ParseError, Expected};
use sipha_core::{span::Span, traits::TokenKind};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum Token { Ident, Plus }
impl TokenKind for Token { fn is_trivia(&self) -> bool { false } }
let error = ParseError::Expected {
expected: Expected::Single(Token::Ident),
found: Some(Token::Plus),
span: Span::new(0..1),
rule_context: None,
context_stack: vec![],
};
#[cfg(feature = "diagnostics")]
{
use sipha_error::Diagnostic;
let diagnostic = Diagnostic::from_parse_error(&error);
println!("{}", diagnostic.format_with_source("+ 5"));
}
```
## License
This project is licensed under the MIT License - see the [LICENSE](../LICENSE) file for details.