commit 95e9d663796a49fdc2427c7b70fe5f557b0e2cb3 Author: Damian Johnson atagar@torproject.org Date: Fri Apr 5 09:02:59 2013 -0700
Improving error message when get_system_tor_version() can't find tor
When tor is unavailable the error output from get_system_tor_version() is pretty sucky...
Traceback (most recent call last): File "./run_tests.py", line 525, in <module> our_version = stem.version.get_system_tor_version(CONFIG["argument.tor"]) File "/home/atagar/stem/stem/version.py", line 84, in get_system_tor_version raise IOError(exc) IOError: [Errno 2] No such file or directory
Making it more developer friendly. --- stem/version.py | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/stem/version.py b/stem/version.py index fa0c0fe..cef5487 100644 --- a/stem/version.py +++ b/stem/version.py @@ -55,6 +55,7 @@ easily parsed and compared, for instance... ===================================== =========== """
+import os import re
import stem.util.enum @@ -77,10 +78,19 @@ def get_system_tor_version(tor_cmd = "tor"): """
if not tor_cmd in VERSION_CACHE: + version_cmd = "%s --version" % tor_cmd + try: - version_cmd = "%s --version" % tor_cmd version_output = stem.util.system.call(version_cmd) except OSError, exc: + # make the error message nicer if this is due to tor being unavialable + + if "No such file or directory" in str(exc): + if os.path.isabs(tor_cmd): + exc = "Unable to check tor's version. '%s' doesn't exist." % tor_cmd + else: + exc = "Unable to run '%s'. Mabye tor isn't in your PATH?" % version_cmd + raise IOError(exc)
if version_output:
tor-commits@lists.torproject.org