[tor-commits] [stem/master] Re-raise the same type of exception we get in launch_tor()

atagar at torproject.org atagar at torproject.org
Wed Dec 30 15:59:02 UTC 2015


commit ae9d81b279bb51b2f1c3d088b86c7aa310b9db11
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Dec 30 08:01:14 2015 -0800

    Re-raise the same type of exception we get in launch_tor()
    
    On #17946 germn argues we should re-raise our original exception type and I can
    can see that. In normal scenarios we should *only* raise an OSError (as
    documented), but if the caller invokes an exception within us (like
    KeyboardInterrupt) then no reason not to give them that.
---
 stem/process.py       |    8 +-------
 test/integ/process.py |    6 +++---
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/stem/process.py b/stem/process.py
index f2d63f0..08af42c 100644
--- a/stem/process.py
+++ b/stem/process.py
@@ -22,7 +22,6 @@ import os
 import re
 import signal
 import subprocess
-import sys
 import tempfile
 
 import stem.prereq
@@ -166,12 +165,7 @@ def launch_tor(tor_cmd = 'tor', args = None, torrc_path = None, completion_perce
       tor_process.kill()  # don't leave a lingering process
       tor_process.wait()
 
-    exc = sys.exc_info()[1]
-
-    if type(exc) == OSError:
-      raise  # something we're raising ourselves
-    else:
-      raise OSError('Unexpected exception while starting tor (%s): %s' % (type(exc).__name__, exc))
+    raise
   finally:
     if timeout:
       signal.alarm(0)  # stop alarm
diff --git a/test/integ/process.py b/test/integ/process.py
index 3b44ef5..1cce8c7 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -212,11 +212,11 @@ class TestProcess(unittest.TestCase):
       try:
         stem.process.launch_tor()
         self.fail("tor shoudn't have started")
-      except OSError as exc:
+      except KeyboardInterrupt as exc:
         if os.path.exists('/proc/%s' % mock_tor_process.pid):
-          self.fail("launch_tor() left a lingering tor process")
+          self.fail('launch_tor() left a lingering tor process')
 
-        self.assertEqual('Unexpected exception while starting tor (KeyboardInterrupt): nope', str(exc))
+        self.assertEqual('nope', str(exc))
 
   def test_torrc_arguments(self):
     """



More information about the tor-commits mailing list