diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2010-10-14 10:35:26 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2010-10-14 10:39:23 +0200 |
commit | 87d2affc0fbe7cf864fdad4eca506d9d06a0de0c (patch) | |
tree | 7125dd3bd9a8fec474accd60bff36b6f221a08a2 /lib | |
parent | 0de1116a4d27cfdb2a0d4e8df00f16527e1566bd (diff) |
safe_exec fixes
Some plugins (ri, fortune) wrap safe_exec in begin/rescue blocks that
did not get triggered because the exceptions from the execution were
caught in the popen block (and would never get exposed anyway). Fix this
by raising if $? does not indicate success.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbot/core/utils/utils.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/rbot/core/utils/utils.rb b/lib/rbot/core/utils/utils.rb index fb9b1f65..4105fa12 100644 --- a/lib/rbot/core/utils/utils.rb +++ b/lib/rbot/core/utils/utils.rb @@ -275,10 +275,12 @@ module ::Irc # Execute an external program, returning a String obtained by redirecting # the program's standards errors and output # + # TODO: find a way to expose some common errors (e.g. Errno::NOENT) + # to the caller def Utils.safe_exec(command, *args) - IO.popen("-") { |p| + output = IO.popen("-") { |p| if p - return p.readlines.join("\n") + break p.readlines.join("\n") else begin $stderr.reopen($stdout) @@ -291,6 +293,8 @@ module ::Irc Kernel::exit! 1 end } + raise "safe execution of #{command} returned #{$?}" unless $?.success? + return output end # Try executing an external program, returning true if the run was successful |