Ruby lint error 用保护子句写这个的正确方法是什么

Ruby lint error what is the right way to write this with a guard clause

正在尝试 运行 一个命令,如果成功则继续,如果失败则引发错误并将命令输出发送到控制台。

output = `#{command}`
unless $CHILD_STATUS.success?
  raise "#{command} failed with:\n#{output}"
end

C: Use a guard clause instead of wrapping the code inside a conditional expression.

代码运行正常,但 rubocop 不喜欢它。改进这段代码的风格并仍然给我相同功能的最佳方法是什么?

试试这个

raise "#{command} failed with:\n#{output}" unless $CHILD_STATUS.success?