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), UnrecognizedIdent(String),
/// An entid->ident mapping failed. /// An entid->ident mapping failed.
/// We also use this error if you try to transact an entid that we didn't allocate, #[fail(display = "no ident found for entid: {}", _0)]
/// 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)]
UnrecognizedEntid(Entid), 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)] #[fail(display = "unknown attribute for entid: {}", _0)]
UnknownAttribute(Entid), 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) { if self.partition_map.contains_entid(e) {
Ok(KnownEntid(e)) Ok(KnownEntid(e))
} else { } 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()) { match conn.transact(&mut sqlite, t.as_str()) {
Err(MentatError::DbError(e)) => { 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), x => panic!("expected db error, got {:?}", x),
} }
@ -923,7 +923,7 @@ mod tests {
match conn.transact(&mut sqlite, t.as_str()) { match conn.transact(&mut sqlite, t.as_str()) {
Err(MentatError::DbError(e)) => { Err(MentatError::DbError(e)) => {
// All this, despite this being the ID we were about to allocate! // 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), x => panic!("expected db error, got {:?}", x),
} }