Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add command to `execute_command` errors (#31490)

Jarek Radosz51b0903f514c
diff --git a/lib/discourse.rb b/lib/discourse.rb
index d15869e11bd..c9d740237de 100644
--- a/lib/discourse.rb
+++ b/lib/discourse.rb
@@ -169,13 +169,8 @@ module Discourse
stdout, stderr, status = Open3.capture3(*args, chdir: chdir)
if !status.exited? || !success_status_codes.include?(status.exitstatus)
- failure_message = "#{failure_message}\n" if !failure_message.blank?
- raise CommandError.new(
- "#{caller[0]}: #{failure_message}#{stderr}",
- stdout: stdout,
- stderr: stderr,
- status: status,
- )
+ message = [command, failure_message, stderr].filter(&:present?).join("\n")
+ raise CommandError.new(message, stdout: stdout, stderr: stderr, status: status)
end
stdout
diff --git a/spec/lib/discourse_spec.rb b/spec/lib/discourse_spec.rb
index 610166208b3..2838ec9db0e 100644
--- a/spec/lib/discourse_spec.rb
+++ b/spec/lib/discourse_spec.rb
@@ -550,6 +550,12 @@ RSpec.describe Discourse do
"a b c",
)
end
+
+ it "includes the command in the error message" do
+ expect do
+ Discourse::Utils.execute_command("false", failure_message: "oops")
+ end.to raise_error(RuntimeError, "false\noops")
+ end
end
describe ".clear_all_theme_cache!" do