[tor-commits] [stem/master] Included last tor warning or error in launch_tor exceptions

atagar at torproject.org atagar at torproject.org
Fri May 18 15:43:04 UTC 2012


commit 47c9ddd8e460488abad58afb8893a1524e37835c
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu May 17 09:59:24 2012 -0700

    Included last tor warning or error in launch_tor exceptions
    
    Adding the last tor waring or error message that's probably useful for figuring
    out the reason why tor failed to launch.
---
 stem/process.py |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/stem/process.py b/stem/process.py
index 94c4212..32bf1a7 100644
--- a/stem/process.py
+++ b/stem/process.py
@@ -81,6 +81,8 @@ def launch_tor(tor_cmd = "tor", options = None, torrc_path = None, completion_pe
     signal.alarm(timeout)
   
   bootstrap_line = re.compile("Bootstrapped ([0-9]+)%: ")
+  problem_line = re.compile("\[(warn|err)\] (.*)$")
+  last_problem = "Timed out"
   
   while True:
     init_line = tor_process.stdout.readline().strip()
@@ -88,13 +90,14 @@ def launch_tor(tor_cmd = "tor", options = None, torrc_path = None, completion_pe
     # this will provide empty results if the process is terminated
     if not init_line:
       tor_process.kill() # ... but best make sure
-      raise OSError("process terminated")
+      raise OSError("Process terminated: %s" % last_problem)
     
     # provide the caller with the initialization message if they want it
     if init_msg_handler: init_msg_handler(init_line)
     
     # return the process if we're done with bootstrapping
     bootstrap_match = bootstrap_line.search(init_line)
+    problem_match = problem_line.search(init_line)
     
     if bootstrap_match and int(bootstrap_match.groups()[0]) >= completion_percent:
       if temp_file:
@@ -102,4 +105,10 @@ def launch_tor(tor_cmd = "tor", options = None, torrc_path = None, completion_pe
         except: pass
       
       return tor_process
+    elif problem_match:
+      runlevel, msg = problem_match.groups()
+      
+      if not "see warnings above" in msg:
+        if ": " in msg: msg = msg.split(": ")[-1].strip()
+        last_problem = msg
 





More information about the tor-commits mailing list