diff options
author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2021-02-13 22:01:11 +0300 |
---|---|---|
committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2021-02-13 22:01:11 +0300 |
commit | 349b8b0f4fb1c2b86f913e1840f15c052ff43c24 (patch) | |
tree | c068b5a22e7af4c36e1bab8f7eb6195ac0e04c37 /lib/pleroma/migrators | |
parent | 5992382cf86d89879b7a8e2dcbf26e910634a73a (diff) | |
download | pleroma-349b8b0f4fb1c2b86f913e1840f15c052ff43c24.tar.gz |
[#3213] `rescue` around potentially-raising `Repo.insert_all/_` calls. Misc. improvements (docs etc.).
Diffstat (limited to 'lib/pleroma/migrators')
-rw-r--r-- | lib/pleroma/migrators/hashtags_table_migrator.ex | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/pleroma/migrators/hashtags_table_migrator.ex b/lib/pleroma/migrators/hashtags_table_migrator.ex index c53f6be12..432c3401a 100644 --- a/lib/pleroma/migrators/hashtags_table_migrator.ex +++ b/lib/pleroma/migrators/hashtags_table_migrator.ex @@ -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 |