diff --git a/query-projector/src/errors.rs b/query-projector/src/errors.rs index d25366eb..0d500c64 100644 --- a/query-projector/src/errors.rs +++ b/query-projector/src/errors.rs @@ -10,17 +10,16 @@ use std; // To refer to std::result::Result. -use failure::{ - Error, -}; +use rusqlite; use mentat_core::{ ValueTypeSet, }; - +use mentat_db; use mentat_query::{ PlainSymbol, }; +use mentat_query_pull; use aggregates::{ SimpleAggregationOp, @@ -33,7 +32,7 @@ macro_rules! bail { ) } -pub type Result = std::result::Result; +pub type Result = std::result::Result; #[derive(Debug, Fail)] pub enum ProjectorError { @@ -62,4 +61,33 @@ pub enum ProjectorError { #[fail(display = "min/max expressions: {} (max 1), corresponding: {}", _0, _1)] AmbiguousAggregates(usize, usize), + + // It would be better to capture the underlying `rusqlite::Error`, but that type doesn't + // implement many useful traits, including `Clone`, `Eq`, and `PartialEq`. + #[fail(display = "SQL error: _0")] + RusqliteError(String), + + #[fail(display = "{}", _0)] + DbError(#[cause] mentat_db::DbError), + + #[fail(display = "{}", _0)] + PullError(#[cause] mentat_query_pull::PullError), +} + +impl From for ProjectorError { + fn from(error: rusqlite::Error) -> ProjectorError { + ProjectorError::RusqliteError(error.to_string()) + } +} + +impl From for ProjectorError { + fn from(error: mentat_db::DbError) -> ProjectorError { + ProjectorError::DbError(error) + } +} + +impl From for ProjectorError { + fn from(error: mentat_query_pull::PullError) -> ProjectorError { + ProjectorError::PullError(error) + } } diff --git a/query-projector/src/lib.rs b/query-projector/src/lib.rs index c74fcc31..de80ca8e 100644 --- a/query-projector/src/lib.rs +++ b/query-projector/src/lib.rs @@ -112,7 +112,7 @@ pub use relresult::{ StructuredRelResult, }; -use errors::{ +pub use errors::{ ProjectorError, Result, }; diff --git a/query-projector/tests/aggregates.rs b/query-projector/tests/aggregates.rs index 584f6431..d2d676ea 100644 --- a/query-projector/tests/aggregates.rs +++ b/query-projector/tests/aggregates.rs @@ -101,7 +101,7 @@ fn test_the_without_max_or_min() { use ::mentat_query_projector::errors::{ ProjectorError, }; - match projection.err().expect("expected failure").downcast().expect("expected specific error") { + match projection.err().expect("expected failure") { ProjectorError::InvalidProjection(s) => { assert_eq!(s.as_str(), "Warning: used `the` without `min` or `max`."); },