A platform for community discussion. Free, open, simple.
DEV: Extensively use `exception: true` in `system()` (#25911)
Jarek Radosz3736d66f17e3
diff --git a/lib/tasks/annotate.rake b/lib/tasks/annotate.rakeindex 57bc0129ac3..56551659d88 100644--- a/lib/tasks/annotate.rake+++ b/lib/tasks/annotate.rake@@ -2,7 +2,7 @@desc "ensure the asynchronously-created post_search_data index is present"task "annotate" => :environment do |task, args|- raise if !system "bin/annotate --models"+ system("bin/annotate --models", exception: true)STDERR.puts "Annotate executed successfully"non_core_plugins =@@ -27,9 +27,12 @@ task "annotate:clean" => :environment do |task, args|db = TemporaryDb.newdb.startdb.with_env do- raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/rake db:migrate"- raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/rake annotate:ensure_all_indexes"- raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/annotate --models --model-dir app/models"+ system("RAILS_ENV=test LOAD_PLUGINS=0 bin/rake db:migrate", exception: true)+ system("RAILS_ENV=test LOAD_PLUGINS=0 bin/rake annotate:ensure_all_indexes", exception: true)+ system(+ "RAILS_ENV=test LOAD_PLUGINS=0 bin/annotate --models --model-dir app/models",+ exception: true,+ )endSTDERR.puts "Annotate executed successfully"ensurediff --git a/lib/tasks/db.rake b/lib/tasks/db.rakeindex 006a6a06ea0..4199f981d72 100644--- a/lib/tasks/db.rake+++ b/lib/tasks/db.rake@@ -27,7 +27,10 @@ endtask "db:environment:set" => [:load_config] do |_, args|if MultisiteTestHelpers.load_multisite?- system("RAILS_ENV=test RAILS_DB=discourse_test_multisite rake db:environment:set")+ system(+ "RAILS_ENV=test RAILS_DB=discourse_test_multisite rake db:environment:set",+ exception: true,+ )endend@@ -56,7 +59,7 @@ endtask "db:drop" => [:load_config] do |_, args|if MultisiteTestHelpers.create_multisite?- system("RAILS_DB=discourse_test_multisite RAILS_ENV=test rake db:drop")+ system("RAILS_DB=discourse_test_multisite RAILS_ENV=test rake db:drop", exception: true)endend@@ -266,7 +269,7 @@ task "db:migrate" => %w[endif !Discourse.is_parallel_test? && MultisiteTestHelpers.load_multisite?- system("RAILS_DB=discourse_test_multisite rake db:migrate")+ system("RAILS_DB=discourse_test_multisite rake db:migrate", exception: true)endenddiff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rakeindex 0e63464091d..2ed9dfcb428 100644--- a/lib/tasks/javascript.rake+++ b/lib/tasks/javascript.rake@@ -46,7 +46,7 @@ def write_template(path, task_name, template)File.write(output_path, "#{header}\n\n#{template}")puts "#{basename} created"- `yarn run prettier --write #{output_path}`+ system("yarn run prettier --write #{output_path}", exception: true)puts "#{basename} prettified"end@@ -59,7 +59,7 @@ def write_hbs_template(path, task_name, template)basename = File.basename(path)output_path = "#{Rails.root}/app/assets/javascripts/#{path}"File.write(output_path, "#{header}\n#{template}")- `yarn run prettier --write #{output_path}`+ system("yarn run prettier --write #{output_path}", exception: true)puts "#{basename} created"end@@ -203,8 +203,7 @@ endtask "javascript:update" => "clean_up" dorequire "uglifier"- yarn = system("yarn install")- abort('Unable to run "yarn install"') unless yarn+ system("yarn install", exception: true)versions = {}start = Time.nowdiff --git a/lib/tasks/qunit.rake b/lib/tasks/qunit.rakeindex 51eb704b140..c8fe5bf123b 100644--- a/lib/tasks/qunit.rake+++ b/lib/tasks/qunit.rake@@ -17,7 +17,7 @@ task "qunit:test", %i[timeout qunit_path filter] do |_, args|report_requests = ENV["REPORT_REQUESTS"] == "1"- system("yarn install")+ system("yarn install", exception: true)# ensure we have this port availabledef port_available?(port)@@ -108,7 +108,13 @@ task "qunit:test", %i[timeout qunit_path filter] do |_, args|if qunit_path# Bypass `ember test` - it only works properly for the `/tests` path.# We have to trigger a `build` manually so that JS is available for rails to serve.- system("yarn", "ember", "build", chdir: "#{Rails.root}/app/assets/javascripts/discourse")+ system(+ "yarn",+ "ember",+ "build",+ chdir: "#{Rails.root}/app/assets/javascripts/discourse",+ exception: true,+ )env["THEME_TEST_PAGES"] = if ENV["THEME_IDS"]ENV["THEME_IDS"]diff --git a/lib/tasks/smoke_test.rake b/lib/tasks/smoke_test.rakeindex cab344e3946..46739a268b3 100644--- a/lib/tasks/smoke_test.rake+++ b/lib/tasks/smoke_test.rake@@ -10,7 +10,7 @@ task "smoke:test" doabort err.messageend- system("yarn install")+ system("yarn install", exception: true)url = ENV["URL"]if !urldiff --git a/lib/tasks/svg_icons.rake b/lib/tasks/svg_icons.rakeindex 7f443447091..7255faba322 100644--- a/lib/tasks/svg_icons.rake+++ b/lib/tasks/svg_icons.rake@@ -9,8 +9,7 @@ def library_srcendtask "svgicons:update" do- yarn = system("yarn install")- abort('Unable to run "yarn install"') unless yarn+ system("yarn install", exception: true)dependencies = [{ source: "@fortawesome/fontawesome-free/sprites", destination: "fontawesome" }]diff --git a/migrations/spec/import_spec.rb b/migrations/spec/import_spec.rbindex 683b2d32d0c..1e40bf5cdef 100644--- a/migrations/spec/import_spec.rb+++ b/migrations/spec/import_spec.rb@@ -1,7 +1,7 @@# frozen_string_literal: trueRSpec.describe "Migrations::Import" do- subject(:cli) { system "migrations/import" }+ subject(:cli) { system("migrations/import", exception: true) }it "works" doexpect { cli }.to output(