[#3213] `rescue` around potentially-raising `Repo.insert_all/_` calls. Misc. improvem...
[akkoma] / lib / pleroma / migrators / hashtags_table_migrator.ex
index c53f6be127188104a1d8a510186a98bcbf317f9c..432c3401a1b4ccc72037fdb40658a591a9d0bc49 100644 (file)
@@ -214,15 +214,20 @@ defmodule Pleroma.Migrators.HashtagsTableMigrator do
         maps = Enum.map(hashtag_records, &%{hashtag_id: &1.id, object_id: object.id})
         expected_rows = length(hashtag_records)
 
-        with {^expected_rows, _} <- Repo.insert_all("hashtags_objects", maps) do
-          object.id
-        else
+        base_error =
+          "ERROR when inserting #{expected_rows} hashtags_objects for obj. #{object.id}"
+
+        try do
+          with {^expected_rows, _} <- Repo.insert_all("hashtags_objects", maps) do
+            object.id
+          else
+            e ->
+              Logger.error("#{base_error}: #{inspect(e)}")
+              Repo.rollback(object.id)
+          end
+        rescue
           e ->
-            error =
-              "ERROR when inserting #{expected_rows} hashtags_objects " <>
-                "for object #{object.id}: #{inspect(e)}"
-
-            Logger.error(error)
+            Logger.error("#{base_error}: #{inspect(e)}")
             Repo.rollback(object.id)
         end
       else