diff --git a/src/conn.rs b/src/conn.rs index 140c890f..c4510b52 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -185,7 +185,7 @@ pub trait Pullable { } pub trait Syncable { - fn sync(&mut self, server_uri: &String, user_uuid: &String) -> ::std::result::Result<(), ::failure::Error>; + fn sync(&mut self, server_uri: &String, user_uuid: &String) -> Result<()>; } /// Represents an in-progress, not yet committed, set of changes to the store. diff --git a/src/errors.rs b/src/errors.rs index 337aad52..dfb84d0b 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -29,6 +29,7 @@ use mentat_query_algebrizer; use mentat_query_projector; use mentat_query_pull; use mentat_sql; +use mentat_tolstoy; pub type Result = std::result::Result; @@ -105,6 +106,9 @@ pub enum MentatError { #[fail(display = "{}", _0)] SQLError(#[cause] mentat_sql::SQLError), + + #[fail(display = "{}", _0)] + TolstoyError(#[cause] mentat_tolstoy::TolstoyError), } impl From for MentatError { @@ -154,3 +158,9 @@ impl From for MentatError { MentatError::SQLError(error) } } + +impl From for MentatError { + fn from(error: mentat_tolstoy::TolstoyError) -> MentatError { + MentatError::TolstoyError(error) + } +} diff --git a/src/store.rs b/src/store.rs index 52a37d5c..b11deddf 100644 --- a/src/store.rs +++ b/src/store.rs @@ -234,7 +234,7 @@ impl Pullable for Store { } impl Syncable for Store { - fn sync(&mut self, server_uri: &String, user_uuid: &String) -> ::std::result::Result<(), ::failure::Error> { + fn sync(&mut self, server_uri: &String, user_uuid: &String) -> Result<()> { let uuid = Uuid::parse_str(&user_uuid).map_err(|_| MentatError::BadUuid(user_uuid.clone()))?; Ok(Syncer::flow(&mut self.sqlite, server_uri, &uuid)?) } diff --git a/tolstoy/src/errors.rs b/tolstoy/src/errors.rs index 3b0a2e3c..7c633632 100644 --- a/tolstoy/src/errors.rs +++ b/tolstoy/src/errors.rs @@ -8,9 +8,13 @@ // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. -#![allow(dead_code)] +use std; +use rusqlite; +use uuid; +use hyper; +use serde_json; -use failure::Error; +use mentat_db; #[macro_export] macro_rules! bail { @@ -19,7 +23,7 @@ macro_rules! bail { ) } -pub type Result = ::std::result::Result; +pub type Result = ::std::result::Result; #[derive(Debug, Fail)] pub enum TolstoyError { @@ -40,4 +44,69 @@ pub enum TolstoyError { #[fail(display = "not yet implemented: {}", _0)] NotYetImplemented(String), + + #[fail(display = "{}", _0)] + DbError(#[cause] mentat_db::DbError), + + #[fail(display = "{}", _0)] + SerializationError(#[cause] serde_json::Error), + + // 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)] + IoError(#[cause] std::io::Error), + + #[fail(display = "{}", _0)] + UuidError(#[cause] uuid::ParseError), + + #[fail(display = "{}", _0)] + NetworkError(#[cause] hyper::Error), + + #[fail(display = "{}", _0)] + UriError(#[cause] hyper::error::UriError), +} + +impl From for TolstoyError { + fn from(error: mentat_db::DbError) -> TolstoyError { + TolstoyError::DbError(error) + } +} + +impl From for TolstoyError { + fn from(error: serde_json::Error) -> TolstoyError { + TolstoyError::SerializationError(error) + } +} + +impl From for TolstoyError { + fn from(error: rusqlite::Error) -> TolstoyError { + TolstoyError::RusqliteError(error.to_string()) + } +} + +impl From for TolstoyError { + fn from(error: std::io::Error) -> TolstoyError { + TolstoyError::IoError(error) + } +} + +impl From for TolstoyError { + fn from(error: uuid::ParseError) -> TolstoyError { + TolstoyError::UuidError(error) + } +} + +impl From for TolstoyError { + fn from(error: hyper::Error) -> TolstoyError { + TolstoyError::NetworkError(error) + } +} + +impl From for TolstoyError { + fn from(error: hyper::error::UriError) -> TolstoyError { + TolstoyError::UriError(error) + } }