Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
fix: handle SQLite bind errors instead of panicing
Lars Wirzenius committed 1 year ago
commit ba999b971957fdbdeb48ccd1acb4917a4780d7c1
parent a123034ead8b218cc9c2c0b8a47f195c6698b822
1 file changed +12 -4
modified src/db.rs
@@ -117,8 +117,12 @@ impl Db {
    /// Create the counter with an initial value. Only use this if
    /// there isn't a counter row already.
    pub fn create_counter(&self, counter: i64) -> Result<(), DbError> {
-
        let mut insert = self.prepare("INSERT INTO counter_test (counter) VALUES (:1)")?;
-
        insert.stmt.bind((1, counter)).unwrap();
+
        let sql = "INSERT INTO counter_test (counter) VALUES (:1)";
+
        let mut insert = self.prepare(sql)?;
+
        insert
+
            .stmt
+
            .bind((1, counter))
+
            .map_err(|e| DbError::bind(sql, e))?;
        match insert.stmt.next() {
            Ok(_) => (),
            Err(e) => return Err(DbError::insert_counter(&insert.sql, e)),
@@ -128,8 +132,12 @@ impl Db {

    /// Update the counter to have a new value.
    pub fn update_counter(&self, counter: i64) -> Result<(), DbError> {
-
        let mut update = self.prepare("UPDATE counter_test SET counter = :1")?;
-
        update.stmt.bind((1, counter)).unwrap();
+
        let sql = "UPDATE counter_test SET counter = :1";
+
        let mut update = self.prepare(sql)?;
+
        update
+
            .stmt
+
            .bind((1, counter))
+
            .map_err(|e| DbError::bind(sql, e))?;
        match update.stmt.next() {
            Ok(_) => (),
            Err(e) => return Err(DbError::update_counter(&update.sql, e)),