Browse Source

Error out if we have not deleted anything

Mark Rousskov 5 năm trước cách đây
mục cha
commit
2c3a643526
2 tập tin đã thay đổi với 11 bổ sung7 xóa
  1. 10 6
      src/db/notifications.rs
  2. 1 1
      src/zulip.rs

+ 10 - 6
src/db/notifications.rs

@@ -43,12 +43,16 @@ pub async fn delete_ping(
 ) -> anyhow::Result<()> {
     match identifier {
         Identifier::Url(origin_url) => {
-            db.execute(
-                "DELETE FROM notifications WHERE user_id = $1 and origin_url = $2",
-                &[&user_id, &origin_url],
-            )
-            .await
-            .context("delete notification query")?;
+            let count = db
+                .execute(
+                    "DELETE FROM notifications WHERE user_id = $1 and origin_url = $2",
+                    &[&user_id, &origin_url],
+                )
+                .await
+                .context("delete notification query")?;
+            if count == 0 {
+                anyhow::bail!("Did not delete any rows");
+            }
         }
         Identifier::Index(idx) => loop {
             let t = db

+ 1 - 1
src/zulip.rs

@@ -70,7 +70,7 @@ pub async fn respond(ctx: &Context, req: Request) -> String {
             Ok(r) => r,
             Err(e) => serde_json::to_string(&Response {
                 content: &format!(
-                    "Failed to parse acknowledgement, expected `acknowledge <url>`: {:?}.",
+                    "Failed to parse acknowledgement, expected `acknowledge <identifier>`: {:?}.",
                     e
                 ),
             })