Convert query-projector/ to ProjectorError.

This commit is contained in:
Nick Alexander 2018-06-27 13:05:04 -07:00
parent af005a7669
commit b2249f189d
3 changed files with 35 additions and 7 deletions

View file

@ -10,17 +10,16 @@
use std; // To refer to std::result::Result. use std; // To refer to std::result::Result.
use failure::{ use rusqlite;
Error,
};
use mentat_core::{ use mentat_core::{
ValueTypeSet, ValueTypeSet,
}; };
use mentat_db;
use mentat_query::{ use mentat_query::{
PlainSymbol, PlainSymbol,
}; };
use mentat_query_pull;
use aggregates::{ use aggregates::{
SimpleAggregationOp, SimpleAggregationOp,
@ -33,7 +32,7 @@ macro_rules! bail {
) )
} }
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, ProjectorError>;
#[derive(Debug, Fail)] #[derive(Debug, Fail)]
pub enum ProjectorError { pub enum ProjectorError {
@ -62,4 +61,33 @@ pub enum ProjectorError {
#[fail(display = "min/max expressions: {} (max 1), corresponding: {}", _0, _1)] #[fail(display = "min/max expressions: {} (max 1), corresponding: {}", _0, _1)]
AmbiguousAggregates(usize, usize), 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<rusqlite::Error> for ProjectorError {
fn from(error: rusqlite::Error) -> ProjectorError {
ProjectorError::RusqliteError(error.to_string())
}
}
impl From<mentat_db::DbError> for ProjectorError {
fn from(error: mentat_db::DbError) -> ProjectorError {
ProjectorError::DbError(error)
}
}
impl From<mentat_query_pull::PullError> for ProjectorError {
fn from(error: mentat_query_pull::PullError) -> ProjectorError {
ProjectorError::PullError(error)
}
} }

View file

@ -112,7 +112,7 @@ pub use relresult::{
StructuredRelResult, StructuredRelResult,
}; };
use errors::{ pub use errors::{
ProjectorError, ProjectorError,
Result, Result,
}; };

View file

@ -101,7 +101,7 @@ fn test_the_without_max_or_min() {
use ::mentat_query_projector::errors::{ use ::mentat_query_projector::errors::{
ProjectorError, ProjectorError,
}; };
match projection.err().expect("expected failure").downcast().expect("expected specific error") { match projection.err().expect("expected failure") {
ProjectorError::InvalidProjection(s) => { ProjectorError::InvalidProjection(s) => {
assert_eq!(s.as_str(), "Warning: used `the` without `min` or `max`."); assert_eq!(s.as_str(), "Warning: used `the` without `min` or `max`.");
}, },