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 = ".."
[dependencies]
error-chain = { git = "https://github.com/rnewman/error-chain", branch = "rnewman/sync" }
failure = "0.1.1"
failure_derive = "0.1.1"
[dependencies.rusqlite]
version = "0.13"

View file

@ -8,28 +8,23 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
use std; // To refer to std::result::Result.
use mentat_core::{
Entid,
};
error_chain! {
types {
Error, ErrorKind, ResultExt, Result;
}
use failure::{
Error,
};
errors {
UnnamedAttribute(id: Entid) {
description("unnamed attribute")
display("attribute {:?} has no name", id)
}
pub type Result<T> = std::result::Result<T, Error>;
RepeatedDbId {
description(":db/id repeated")
display(":db/id repeated")
}
}
#[derive(Debug, Fail)]
pub enum PullError {
#[fail(display = "attribute {:?} has no name", _0)]
UnnamedAttribute(Entid),
links {
DbError(::mentat_db::Error, ::mentat_db::ErrorKind);
}
#[fail(display = ":db/id repeated")]
RepeatedDbId,
}

View file

@ -57,8 +57,10 @@
/// [*]))
///! ```
extern crate failure;
#[macro_use]
extern crate error_chain;
extern crate failure_derive;
extern crate rusqlite;
@ -101,7 +103,7 @@ use mentat_query::{
pub mod errors;
use errors::{
ErrorKind,
PullError,
Result,
};
@ -163,7 +165,7 @@ impl Puller {
// In the unlikely event that we have an attribute with no name, we bail.
schema.get_ident(*i)
.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();
@ -192,7 +194,7 @@ impl Puller {
&PullConcreteAttribute::Ident(ref i) if i.as_ref() == db_id.as_ref() => {
// We only allow :db/id once.
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()));
},