Convert query-pull/ to failure.

This commit is contained in:
Grisha Kruglov 2018-06-04 16:10:21 -04:00 committed by Nick Alexander
parent 326fe881a0
commit 061967f268
3 changed files with 20 additions and 22 deletions

View file

@ -4,7 +4,8 @@ version = "0.0.1"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
error-chain = { git = "https://github.com/rnewman/error-chain", branch = "rnewman/sync" } failure = "0.1.1"
failure_derive = "0.1.1"
[dependencies.rusqlite] [dependencies.rusqlite]
version = "0.13" version = "0.13"

View file

@ -8,28 +8,23 @@
// 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.
use std; // To refer to std::result::Result.
use mentat_core::{ use mentat_core::{
Entid, Entid,
}; };
error_chain! { use failure::{
types { Error,
Error, ErrorKind, ResultExt, Result; };
}
errors { pub type Result<T> = std::result::Result<T, Error>;
UnnamedAttribute(id: Entid) {
description("unnamed attribute")
display("attribute {:?} has no name", id)
}
RepeatedDbId { #[derive(Debug, Fail)]
description(":db/id repeated") pub enum PullError {
display(":db/id repeated") #[fail(display = "attribute {:?} has no name", _0)]
} UnnamedAttribute(Entid),
}
links { #[fail(display = ":db/id repeated")]
DbError(::mentat_db::Error, ::mentat_db::ErrorKind); RepeatedDbId,
}
} }

View file

@ -57,8 +57,10 @@
/// [*])) /// [*]))
///! ``` ///! ```
extern crate failure;
#[macro_use] #[macro_use]
extern crate error_chain; extern crate failure_derive;
extern crate rusqlite; extern crate rusqlite;
@ -101,7 +103,7 @@ use mentat_query::{
pub mod errors; pub mod errors;
use errors::{ use errors::{
ErrorKind, PullError,
Result, Result,
}; };
@ -163,7 +165,7 @@ impl Puller {
// In the unlikely event that we have an attribute with no name, we bail. // In the unlikely event that we have an attribute with no name, we bail.
schema.get_ident(*i) schema.get_ident(*i)
.map(|ident| ValueRc::new(ident.clone())) .map(|ident| ValueRc::new(ident.clone()))
.ok_or_else(|| ErrorKind::UnnamedAttribute(*i)) .ok_or_else(|| PullError::UnnamedAttribute(*i))
}; };
let mut names: BTreeMap<Entid, ValueRc<Keyword>> = Default::default(); let mut names: BTreeMap<Entid, ValueRc<Keyword>> = Default::default();
@ -192,7 +194,7 @@ impl Puller {
&PullConcreteAttribute::Ident(ref i) if i.as_ref() == db_id.as_ref() => { &PullConcreteAttribute::Ident(ref i) if i.as_ref() == db_id.as_ref() => {
// We only allow :db/id once. // We only allow :db/id once.
if db_id_alias.is_some() { if db_id_alias.is_some() {
bail!(ErrorKind::RepeatedDbId); Err(PullError::RepeatedDbId)?
} }
db_id_alias = Some(alias.unwrap_or_else(|| db_id.to_value_rc())); db_id_alias = Some(alias.unwrap_or_else(|| db_id.to_value_rc()));
}, },