From 120f0cbb6514ffeb74f0bc3c84bf16df36508614 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Mon, 4 May 2015 20:02:33 -0400 Subject: [PATCH] Add messages to all our assertions. --- src/lib.rs | 12 +++++++++--- src/types.rs | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 69db74a..13007cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -592,7 +592,10 @@ impl<'conn> SqliteStatement<'conn> { self.reset_if_needed(); unsafe { - assert_eq!(params.len() as c_int, ffi::sqlite3_bind_parameter_count(self.stmt)); + assert!(params.len() as c_int == ffi::sqlite3_bind_parameter_count(self.stmt), + "incorrect number of parameters to execute(): expected {}, got {}", + ffi::sqlite3_bind_parameter_count(self.stmt), + params.len()); for (i, p) in params.iter().enumerate() { try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int))); @@ -632,7 +635,10 @@ impl<'conn> SqliteStatement<'conn> { self.reset_if_needed(); unsafe { - assert_eq!(params.len() as c_int, ffi::sqlite3_bind_parameter_count(self.stmt)); + assert!(params.len() as c_int == ffi::sqlite3_bind_parameter_count(self.stmt), + "incorrect number of parameters to query(): expected {}, got {}", + ffi::sqlite3_bind_parameter_count(self.stmt), + params.len()); for (i, p) in params.iter().enumerate() { try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int))); @@ -844,7 +850,7 @@ mod test { END;"; db.execute_batch(sql).unwrap(); } - + let path_string = path.to_str().unwrap(); let db = SqliteConnection::open(&path_string).unwrap(); let the_answer = db.query_row_safe("SELECT x FROM foo", diff --git a/src/types.rs b/src/types.rs index 753cf67..f902a59 100644 --- a/src/types.rs +++ b/src/types.rs @@ -195,7 +195,10 @@ impl FromSql for Vec { let c_blob = ffi::sqlite3_column_blob(stmt, col); let len = ffi::sqlite3_column_bytes(stmt, col); - assert!(len >= 0); let len = len as usize; + // The documentation for sqlite3_column_bytes indicates it is always non-negative, + // but we should assert here just to be sure. + assert!(len >= 0, "unexpected negative return from sqlite3_column_bytes"); + let len = len as usize; Ok(from_raw_parts(mem::transmute(c_blob), len).to_vec()) }