Skip to content

Commit

Permalink
Add exception and error handling
Browse files Browse the repository at this point in the history
We want to catch any exceptions not surfaced by the validations on the model.
Also grouped the tests to be more readible.
  • Loading branch information
lauraghiorghisor-tw committed Dec 5, 2024
1 parent 4202eee commit 392c045
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 162 deletions.
15 changes: 9 additions & 6 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ namespace :assets do
delete_and_update_draft(replacement_asset)
processed_asset_ids[replacement_asset.id.to_s] = true
puts "Asset ID: #{original_asset_id} - OK. Draft replacement #{replacement_asset.id} deleted and updated to false."
rescue StandardError
puts "Asset ID: #{original_asset_id} - ERROR. Asset replacement failed to save. Error: #{replacement_asset.errors.full_messages}."
rescue StandardError => e
message = replacement_asset.errors.full_messages.empty? ? e.message : replacement_asset.errors.full_messages
puts "Asset ID: #{original_asset_id} - ERROR. Asset replacement #{replacement_asset.id} failed to save. Error: #{message}."
end
next
end
Expand All @@ -91,8 +92,9 @@ namespace :assets do
delete_and_update_draft(original_asset)
processed_asset_ids[original_asset_id] = true
puts "Asset ID: #{original_asset_id} - OK. Asset is a replacement. Asset deleted and updated to false."
rescue StandardError
puts "Asset ID: #{original_asset_id} - ERROR. Asset failed to save. Error: #{original_asset.errors.full_messages}."
rescue StandardError => e
message = original_asset.errors.full_messages.empty? ? e.message : original_asset.errors.full_messages
puts "Asset ID: #{original_asset_id} - ERROR. Asset failed to save. Error: #{message}."
end
next
end
Expand All @@ -111,8 +113,9 @@ namespace :assets do
delete_and_update_draft(original_asset, should_update_draft: false)
processed_asset_ids[original_asset_id] = true
puts "Asset ID: #{original_asset_id} - OK. Asset has been deleted."
rescue StandardError
puts "Asset ID: #{original_asset_id} - ERROR. Asset failed to save. Error: #{original_asset.errors.full_messages}."
rescue StandardError => e
message = original_asset.errors.full_messages.empty? ? e : original_asset.errors.full_messages
puts "Asset ID: #{original_asset_id} - ERROR. Asset failed to save. Error: #{message}."
end
end
end
Expand Down
Loading

0 comments on commit 392c045

Please sign in to comment.