Pre: Split a Db error for clarity

error_chain stack limitations no longer apply, so let's have better errors!
This commit is contained in:
Grisha Kruglov 2018-07-25 15:28:48 -07:00 committed by Grisha Kruglov
parent 5bc6d76bb3
commit b8b2aef181
3 changed files with 8 additions and 6 deletions

View file

@ -214,11 +214,13 @@ pub enum DbErrorKind {
UnrecognizedIdent(String),
/// An entid->ident mapping failed.
/// We also use this error if you try to transact an entid that we didn't allocate,
/// in part because we blow the stack in error_chain if we define a new enum!
#[fail(display = "unrecognized or no ident found for entid: {}", _0)]
#[fail(display = "no ident found for entid: {}", _0)]
UnrecognizedEntid(Entid),
/// Tried to transact an entid that isn't allocated.
#[fail(display = "entid not allocated: {}", _0)]
UnallocatedEntid(Entid),
#[fail(display = "unknown attribute for entid: {}", _0)]
UnknownAttribute(Entid),

View file

@ -294,7 +294,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
if self.partition_map.contains_entid(e) {
Ok(KnownEntid(e))
} else {
bail!(DbErrorKind::UnrecognizedEntid(e))
bail!(DbErrorKind::UnallocatedEntid(e))
}
}

View file

@ -895,7 +895,7 @@ mod tests {
match conn.transact(&mut sqlite, t.as_str()) {
Err(MentatError::DbError(e)) => {
assert_eq!(e.kind(), ::db_traits::errors::DbErrorKind::UnrecognizedEntid(next + 1));
assert_eq!(e.kind(), ::db_traits::errors::DbErrorKind::UnallocatedEntid(next + 1));
},
x => panic!("expected db error, got {:?}", x),
}
@ -923,7 +923,7 @@ mod tests {
match conn.transact(&mut sqlite, t.as_str()) {
Err(MentatError::DbError(e)) => {
// All this, despite this being the ID we were about to allocate!
assert_eq!(e.kind(), ::db_traits::errors::DbErrorKind::UnrecognizedEntid(next));
assert_eq!(e.kind(), ::db_traits::errors::DbErrorKind::UnallocatedEntid(next));
},
x => panic!("expected db error, got {:?}", x),
}