From 4f518fd0e765d20a8a8d07bc0a17ef9fbb7bfbb6 Mon Sep 17 00:00:00 2001
From: Greg Heartsfield <scsibug@imap.cc>
Date: Thu, 6 Jun 2024 17:32:13 -0500
Subject: [PATCH] fix: prevent thread panic on large tag values using postgres

Exceptionally large tag values (thousands of characters) can result in
an error from postgres: index row size exceeds btree version 4 maximum
2704 for index "tag_value_idx".  This panics the writer thread, and
prevents further writes from succeeding.

This change simply removes the unwrap, allowing the error to propagate
where it is sent as a write error back to the client.  The error
message could be improved.

https://github.com/scsibug/nostr-rs-relay/issues/196
---
 src/repo/postgres.rs | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/repo/postgres.rs b/src/repo/postgres.rs
index 5a1a28b..4704379 100644
--- a/src/repo/postgres.rs
+++ b/src/repo/postgres.rs
@@ -187,8 +187,7 @@ ON CONFLICT (id) DO NOTHING"#,
                                 .bind(tag_name)
                                 .bind(hex::decode(tag_val).ok())
                                 .execute(&mut tx)
-                                .await
-                                .unwrap();
+                                .await?;
                         } else {
                             sqlx::query("INSERT INTO tag (event_id, \"name\", value, value_hex) VALUES($1, $2, $3, NULL) \
                     ON CONFLICT (event_id, \"name\", value, value_hex) DO NOTHING")
@@ -196,8 +195,7 @@ ON CONFLICT (id) DO NOTHING"#,
                                 .bind(tag_name)
                                 .bind(tag_val.as_bytes())
                                 .execute(&mut tx)
-                                .await
-                                .unwrap();
+                                .await?;
                         }
                     }
                     None => {}