DEV: Stop if theme:update fails for default site (#15090)

DEV: Stop if theme:update fails for default site (#15090)

The error handling of the theme:update Rake task has been improved. If an error occurs while updating the default site, then the exception will be propagated and the process will exit with non-zero status.

This is a follow-up to commit 3f97f884fef9d3e4b33ae6361d7891c3c414802b.

diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake
index ddc3abb..5dbcae6 100644
--- a/lib/tasks/themes.rake
+++ b/lib/tasks/themes.rake
@@ -52,24 +52,23 @@ task "themes:install" => :environment do |task, args|
   end
 end
 
-def update_themes(fail_stop: true)
+def update_themes
   Theme.includes(:remote_theme).where(enabled: true, auto_update: true).find_each do |theme|
     begin
-      next if theme.remote_theme.blank?
+      remote_theme = theme.remote_theme
+      next if remote_theme.blank?
 
       puts "Updating '#{theme.name}' for '#{RailsMultisite::ConnectionManagement.current_db}'..."
-      theme.remote_theme.update_from_remote
+      remote_theme.update_from_remote
 
-      if theme.remote_theme.last_error_text.present?
-        puts "Error updating '#{theme.name}': #{theme.remote_theme.last_error_text}"
-        exit 1 if fail_stop
-      end
+      raise RemoteTheme::ImportError.new(remote_theme.last_error_text) if remote_theme.last_error_text.present?
     rescue => e
       STDERR.puts "Failed to update '#{theme.name}': #{e}"
-      STDERR.puts e.backtrace
-      exit 1 if fail_stop
+      raise if RailsMultisite::ConnectionManagement.current_db == "default"
     end
   end
+
+  true
 end
 
 desc "Update themes & theme components"
@@ -78,7 +77,7 @@ task "themes:update" => :environment do
     update_themes
   else
     RailsMultisite::ConnectionManagement.each_connection do
-      update_themes(fail_stop: false)
+      update_themes
     end
   end
 end

GitHub sha: b1844c45c3896f8c493687ad5bf6f6865afdc414

This commit appears in #15090 which was approved by CvX. It was merged by udan11.