]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
safe_exec fixes
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 14 Oct 2010 08:35:26 +0000 (10:35 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 14 Oct 2010 08:39:23 +0000 (10:39 +0200)
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.

lib/rbot/core/utils/utils.rb

index fb9b1f651094f42fff7f42654348e80705b197ca..4105fa12db611c0988d5f91d0757c458d44e2168 100644 (file)
@@ -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