Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Include traceback when wrapping import errors #450

wants to merge 1 commit into from

2 participants


Without the complete tracebacks it's fairly frustrating to try and track down the import errors.


Note: I haven't yet tested the multiprocessing and jinja2 handlers. They look like they should work, though, and if this patch is going to be accepted I'll test them properly.

@wolever wolever closed this
@wolever wolever reopened this

I actually think I do display the traceback for the multiprocessing import, for this very reason, but it looks like that was not considered for those other optional requirements. Good catch!

@bitprophet bitprophet was assigned
@bitprophet bitprophet closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 11, 2011
  1. @wolever
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 12 deletions.
  1. +4 −2 fabric/contrib/
  2. +7 −5 fabric/
  3. +12 −5 fabric/
6 fabric/contrib/
@@ -101,8 +101,10 @@ def upload_template(filename, destination, context=None, use_jinja=False,
from jinja2 import Environment, FileSystemLoader
jenv = Environment(loader=FileSystemLoader(template_dir or '.'))
text = jenv.get_template(filename).render(**context or {})
- except ImportError, e:
- abort("tried to use Jinja2 but was unable to import: %s" % e)
+ except ImportError:
+ import traceback
+ tb = traceback.format_exc()
+ abort(tb + "\nCould not import Jinja2 (see traceback above)")
with open(filename) as inputfile:
text =
12 fabric/
@@ -20,11 +20,13 @@
warnings.simplefilter('ignore', DeprecationWarning)
import paramiko as ssh
except ImportError, e:
- print >> sys.stderr, """There was a problem importing our SSH library. Specifically:
- %s
-Please make sure all dependencies are installed and importable.""" % e
+ import traceback
+ import textwrap
+ traceback.print_exc()
+ print >> sys.stderr, textwrap.dedent("""
+ There was a problem importing our SSH library (see traceback above).
+ Please make sure all dependencies are installed and importable.
+ """).rstrip()
17 fabric/
@@ -204,11 +204,18 @@ def execute(task, *args, **kwargs):
# if it can't.
import multiprocessing
- except ImportError, e:
- msg = "At least one task needs to be run in parallel, but the\nmultiprocessing module cannot be imported:"
- msg += "\n\n\t%s\n\n" % e
- msg += "Please make sure the module is installed or that the above ImportError is\nfixed."
- abort(msg)
+ except ImportError:
+ import traceback
+ import textwrap
+ tb = traceback.format_exc()
+ abort(tb + textwrap.dedent("""
+ At least one task needs to be run in parallel, but
+ the multiprocessing module cannot be imported (see
+ traceback, above).
+ Please make sure the module is installed or that
+ the above ImportError is fixed.
+ """).rstrip())
# Wrap in another callable that nukes the child's cached
# connection object, if needed, to prevent shared-socket
Something went wrong with that request. Please try again.