Convert tolstoy/ to failure.
This commit is contained in:
parent
31de5be64f
commit
4e46adeba1
7 changed files with 48 additions and 82 deletions
|
@ -381,9 +381,7 @@ mod testing {
|
||||||
extern crate mentat_db;
|
extern crate mentat_db;
|
||||||
|
|
||||||
// For matching inside a test.
|
// For matching inside a test.
|
||||||
use mentat_db::ErrorKind::{
|
use mentat_db::DbError;
|
||||||
UnrecognizedEntid,
|
|
||||||
};
|
|
||||||
|
|
||||||
use ::{
|
use ::{
|
||||||
Conn,
|
Conn,
|
||||||
|
@ -424,7 +422,7 @@ mod testing {
|
||||||
let mut in_progress = conn.begin_transaction(&mut sqlite).expect("begun successfully");
|
let mut in_progress = conn.begin_transaction(&mut sqlite).expect("begun successfully");
|
||||||
|
|
||||||
// This should fail: unrecognized entid.
|
// This should fail: unrecognized entid.
|
||||||
if let Err(Error(MentatError::DbError(UnrecognizedEntid(e)), _)) = in_progress.transact_terms(terms, tempids) {
|
if let Ok(DbError::UnrecognizedEntid(e)) = in_progress.transact_terms(terms, tempids).expect_err("expected transact to fail").downcast() {
|
||||||
assert_eq!(e, 999);
|
assert_eq!(e, 999);
|
||||||
} else {
|
} else {
|
||||||
panic!("Should have rejected the entid.");
|
panic!("Should have rejected the entid.");
|
||||||
|
|
|
@ -5,6 +5,8 @@ workspace = ".."
|
||||||
authors = ["Grisha Kruglov <gkruglov@mozilla.com>"]
|
authors = ["Grisha Kruglov <gkruglov@mozilla.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
failure = "0.1.1"
|
||||||
|
failure_derive = "0.1.1"
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
hyper = "0.11"
|
hyper = "0.11"
|
||||||
tokio-core = "0.1"
|
tokio-core = "0.1"
|
||||||
|
@ -15,8 +17,6 @@ serde_derive = "1.0"
|
||||||
lazy_static = "0.2"
|
lazy_static = "0.2"
|
||||||
uuid = { version = "0.5", features = ["v4", "serde"] }
|
uuid = { version = "0.5", features = ["v4", "serde"] }
|
||||||
|
|
||||||
error-chain = { git = "https://github.com/rnewman/error-chain", branch = "rnewman/sync" }
|
|
||||||
|
|
||||||
[dependencies.mentat_core]
|
[dependencies.mentat_core]
|
||||||
path = "../core"
|
path = "../core"
|
||||||
|
|
||||||
|
|
|
@ -10,63 +10,34 @@
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use std;
|
use failure::Error;
|
||||||
use hyper;
|
|
||||||
use rusqlite;
|
|
||||||
use uuid;
|
|
||||||
use mentat_db;
|
|
||||||
use serde_cbor;
|
|
||||||
use serde_json;
|
|
||||||
|
|
||||||
error_chain! {
|
#[macro_export]
|
||||||
types {
|
macro_rules! bail {
|
||||||
Error, ErrorKind, ResultExt, Result;
|
($e:expr) => (
|
||||||
}
|
return Err($e.into());
|
||||||
|
)
|
||||||
foreign_links {
|
}
|
||||||
IOError(std::io::Error);
|
|
||||||
HttpError(hyper::Error);
|
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||||
HyperUriError(hyper::error::UriError);
|
|
||||||
SqlError(rusqlite::Error);
|
#[derive(Debug, Fail)]
|
||||||
UuidParseError(uuid::ParseError);
|
pub enum TolstoyError {
|
||||||
Utf8Error(std::str::Utf8Error);
|
#[fail(display = "Received bad response from the server: {}", _0)]
|
||||||
JsonError(serde_json::Error);
|
BadServerResponse(String),
|
||||||
CborError(serde_cbor::error::Error);
|
|
||||||
}
|
#[fail(display = "encountered more than one metadata value for key: {}", _0)]
|
||||||
|
DuplicateMetadata(String),
|
||||||
links {
|
|
||||||
DbError(mentat_db::Error, mentat_db::ErrorKind);
|
#[fail(display = "transaction processor didn't say it was done")]
|
||||||
}
|
TxProcessorUnfinished,
|
||||||
|
|
||||||
errors {
|
#[fail(display = "expected one, found {} uuid mappings for tx", _0)]
|
||||||
TxIncorrectlyMapped(n: usize) {
|
TxIncorrectlyMapped(usize),
|
||||||
description("encountered more than one uuid mapping for tx")
|
|
||||||
display("expected one, found {} uuid mappings for tx", n)
|
#[fail(display = "encountered unexpected state: {}", _0)]
|
||||||
}
|
UnexpectedState(String),
|
||||||
|
|
||||||
UnexpectedState(t: String) {
|
#[fail(display = "not yet implemented: {}", _0)]
|
||||||
description("encountered unexpected state")
|
NotYetImplemented(String),
|
||||||
display("encountered unexpected state: {}", t)
|
|
||||||
}
|
|
||||||
|
|
||||||
NotYetImplemented(t: String) {
|
|
||||||
description("not yet implemented")
|
|
||||||
display("not yet implemented: {}", t)
|
|
||||||
}
|
|
||||||
|
|
||||||
DuplicateMetadata(k: String) {
|
|
||||||
description("encountered more than one metadata value for key")
|
|
||||||
display("encountered more than one metadata value for key: {}", k)
|
|
||||||
}
|
|
||||||
|
|
||||||
TxProcessorUnfinished {
|
|
||||||
description("Tx processor couldn't finish")
|
|
||||||
display("Tx processor couldn't finish")
|
|
||||||
}
|
|
||||||
|
|
||||||
BadServerResponse(s: String) {
|
|
||||||
description("Received bad response from the server")
|
|
||||||
display("Received bad response from the server: {}", s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,9 @@
|
||||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
// specific language governing permissions and limitations under the License.
|
// specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
// For error_chain:
|
extern crate failure;
|
||||||
#![recursion_limit="128"]
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate failure_derive;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
@ -33,16 +31,15 @@ extern crate mentat_core;
|
||||||
extern crate rusqlite;
|
extern crate rusqlite;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
pub mod errors;
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
pub mod tx_processor;
|
pub mod tx_processor;
|
||||||
pub mod errors;
|
|
||||||
pub mod syncer;
|
pub mod syncer;
|
||||||
pub mod tx_mapper;
|
pub mod tx_mapper;
|
||||||
pub use syncer::Syncer;
|
pub use syncer::Syncer;
|
||||||
pub use errors::{
|
pub use errors::{
|
||||||
Error,
|
TolstoyError,
|
||||||
ErrorKind,
|
|
||||||
Result,
|
Result,
|
||||||
ResultExt,
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,7 +15,7 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use schema;
|
use schema;
|
||||||
use errors::{
|
use errors::{
|
||||||
ErrorKind,
|
TolstoyError,
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ impl HeadTrackable for SyncMetadataClient {
|
||||||
let updated = tx.execute("UPDATE tolstoy_metadata SET value = ? WHERE key = ?",
|
let updated = tx.execute("UPDATE tolstoy_metadata SET value = ? WHERE key = ?",
|
||||||
&[&uuid_bytes, &schema::REMOTE_HEAD_KEY])?;
|
&[&uuid_bytes, &schema::REMOTE_HEAD_KEY])?;
|
||||||
if updated != 1 {
|
if updated != 1 {
|
||||||
bail!(ErrorKind::DuplicateMetadata(schema::REMOTE_HEAD_KEY.into()));
|
bail!(TolstoyError::DuplicateMetadata(schema::REMOTE_HEAD_KEY.into()));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ use metadata::HeadTrackable;
|
||||||
use schema::ensure_current_version;
|
use schema::ensure_current_version;
|
||||||
|
|
||||||
use errors::{
|
use errors::{
|
||||||
ErrorKind,
|
TolstoyError,
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ impl Syncer {
|
||||||
let mut uploader = UploadingTxReceiver::new(remote_client, remote_head);
|
let mut uploader = UploadingTxReceiver::new(remote_client, remote_head);
|
||||||
Processor::process(db_tx, from_tx, &mut uploader)?;
|
Processor::process(db_tx, from_tx, &mut uploader)?;
|
||||||
if !uploader.is_done {
|
if !uploader.is_done {
|
||||||
bail!(ErrorKind::TxProcessorUnfinished);
|
bail!(TolstoyError::TxProcessorUnfinished);
|
||||||
}
|
}
|
||||||
// Last tx uuid uploaded by the tx receiver.
|
// Last tx uuid uploaded by the tx receiver.
|
||||||
// It's going to be our new head.
|
// It's going to be our new head.
|
||||||
|
@ -222,7 +222,7 @@ impl Syncer {
|
||||||
// without walking the table at all, and use the tx index.
|
// without walking the table at all, and use the tx index.
|
||||||
Processor::process(&db_tx, None, &mut inquiring_tx_receiver)?;
|
Processor::process(&db_tx, None, &mut inquiring_tx_receiver)?;
|
||||||
if !inquiring_tx_receiver.is_done {
|
if !inquiring_tx_receiver.is_done {
|
||||||
bail!(ErrorKind::TxProcessorUnfinished);
|
bail!(TolstoyError::TxProcessorUnfinished);
|
||||||
}
|
}
|
||||||
let have_local_changes = match inquiring_tx_receiver.last_tx {
|
let have_local_changes = match inquiring_tx_receiver.last_tx {
|
||||||
Some(tx) => {
|
Some(tx) => {
|
||||||
|
@ -257,7 +257,7 @@ impl Syncer {
|
||||||
Syncer::upload_ours(&mut db_tx, Some(upload_from_tx), &remote_client, &remote_head)?;
|
Syncer::upload_ours(&mut db_tx, Some(upload_from_tx), &remote_client, &remote_head)?;
|
||||||
} else {
|
} else {
|
||||||
d(&format!("Unable to fast-forward the server; missing local tx mapping"));
|
d(&format!("Unable to fast-forward the server; missing local tx mapping"));
|
||||||
bail!(ErrorKind::TxIncorrectlyMapped(0));
|
bail!(TolstoyError::TxIncorrectlyMapped(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We diverged from the server.
|
// We diverged from the server.
|
||||||
|
@ -265,7 +265,7 @@ impl Syncer {
|
||||||
} else {
|
} else {
|
||||||
d(&format!("server changed since last sync."));
|
d(&format!("server changed since last sync."));
|
||||||
|
|
||||||
bail!(ErrorKind::NotYetImplemented(
|
bail!(TolstoyError::NotYetImplemented(
|
||||||
format!("Can't yet sync against changed server. Local head {:?}, remote head {:?}", locally_known_remote_head, remote_head)
|
format!("Can't yet sync against changed server. Local head {:?}, remote head {:?}", locally_known_remote_head, remote_head)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ use uuid::Uuid;
|
||||||
use mentat_core::Entid;
|
use mentat_core::Entid;
|
||||||
|
|
||||||
use errors::{
|
use errors::{
|
||||||
ErrorKind,
|
TolstoyError,
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ impl TxMapper {
|
||||||
if txs.len() == 0 {
|
if txs.len() == 0 {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
} else if txs.len() > 1 {
|
} else if txs.len() > 1 {
|
||||||
bail!(ErrorKind::TxIncorrectlyMapped(txs.len()));
|
bail!(TolstoyError::TxIncorrectlyMapped(txs.len()));
|
||||||
}
|
}
|
||||||
Ok(Some(txs.remove(0)?))
|
Ok(Some(txs.remove(0)?))
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ impl TxMapper {
|
||||||
if uuids.len() == 0 {
|
if uuids.len() == 0 {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
} else if uuids.len() > 1 {
|
} else if uuids.len() > 1 {
|
||||||
bail!(ErrorKind::TxIncorrectlyMapped(uuids.len()));
|
bail!(TolstoyError::TxIncorrectlyMapped(uuids.len()));
|
||||||
}
|
}
|
||||||
Ok(Some(uuids.remove(0)?))
|
Ok(Some(uuids.remove(0)?))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue