Use TolstoyError for tolstoy's Results; wrap tolstoy's dependency errors r=nalexander
This is inline with the rest of mentat, and helps with upcoming tolstoy work.
This commit is contained in:
parent
5fe4f12d32
commit
8af5288a60
4 changed files with 84 additions and 5 deletions
|
@ -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.
|
||||
|
|
|
@ -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<T> = std::result::Result<T, MentatError>;
|
||||
|
||||
|
@ -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<std::io::Error> for MentatError {
|
||||
|
@ -154,3 +158,9 @@ impl From<mentat_sql::SQLError> for MentatError {
|
|||
MentatError::SQLError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<mentat_tolstoy::TolstoyError> for MentatError {
|
||||
fn from(error: mentat_tolstoy::TolstoyError) -> MentatError {
|
||||
MentatError::TolstoyError(error)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)?)
|
||||
}
|
||||
|
|
|
@ -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<T> = ::std::result::Result<T, Error>;
|
||||
pub type Result<T> = ::std::result::Result<T, TolstoyError>;
|
||||
|
||||
#[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<mentat_db::DbError> for TolstoyError {
|
||||
fn from(error: mentat_db::DbError) -> TolstoyError {
|
||||
TolstoyError::DbError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for TolstoyError {
|
||||
fn from(error: serde_json::Error) -> TolstoyError {
|
||||
TolstoyError::SerializationError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rusqlite::Error> for TolstoyError {
|
||||
fn from(error: rusqlite::Error) -> TolstoyError {
|
||||
TolstoyError::RusqliteError(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for TolstoyError {
|
||||
fn from(error: std::io::Error) -> TolstoyError {
|
||||
TolstoyError::IoError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<uuid::ParseError> for TolstoyError {
|
||||
fn from(error: uuid::ParseError) -> TolstoyError {
|
||||
TolstoyError::UuidError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<hyper::Error> for TolstoyError {
|
||||
fn from(error: hyper::Error) -> TolstoyError {
|
||||
TolstoyError::NetworkError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<hyper::error::UriError> for TolstoyError {
|
||||
fn from(error: hyper::error::UriError) -> TolstoyError {
|
||||
TolstoyError::UriError(error)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue