crates/kleene-gql/src/error.rs
use std::fmt;
/// Why a query was refused or failed.
#[derive(Debug)]
#[non_exhaustive]
pub enum GqlError {
/// The text does not parse.
Syntax {
/// Byte offset in the query.
pos: usize,
/// What was wrong.
msg: String,
},
/// The query parses but names something unknown or unbound.
Semantic(String),
/// Valid GQL this client does not run (yet).
Unsupported(String),
/// The plan refused or failed.
Plan(kleene_plan::PlanError),
}
impl fmt::Display for GqlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GqlError::Syntax { pos, msg } => write!(f, "syntax error at {pos}: {msg}"),
GqlError::Semantic(m) => write!(f, "{m}"),
GqlError::Unsupported(m) => write!(f, "not supported: {m}"),
GqlError::Plan(e) => write!(f, "plan: {e}"),
}
}
}
impl std::error::Error for GqlError {}
impl From<kleene_plan::PlanError> for GqlError {
fn from(e: kleene_plan::PlanError) -> Self {
GqlError::Plan(e)
}
}
/// The result of a fallible operation of this crate.
pub type Result<T> = std::result::Result<T, GqlError>;