Skip to main content

amql_engine/
error.rs

1//! Structured error types for the AQL engine.
2
3use std::fmt;
4
5/// Error type for AQL operations.
6///
7/// Wraps a descriptive error message and implements `std::error::Error`,
8/// enabling integration with `anyhow` and other error-handling crates.
9#[derive(Debug, Clone)]
10pub struct AqlError(String);
11
12impl AqlError {
13    /// Create a new error with the given message.
14    pub fn new(msg: impl fmt::Display) -> Self {
15        Self(msg.to_string())
16    }
17
18    /// Access the inner error message.
19    pub fn message(&self) -> &str {
20        &self.0
21    }
22}
23
24impl fmt::Display for AqlError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        f.write_str(&self.0)
27    }
28}
29
30impl std::error::Error for AqlError {}
31
32impl From<String> for AqlError {
33    fn from(s: String) -> Self {
34        Self(s)
35    }
36}
37
38impl From<&str> for AqlError {
39    fn from(s: &str) -> Self {
40        Self(s.to_owned())
41    }
42}