|
5 | 5 |
|
6 | 6 | from future import standard_library |
7 | 7 | standard_library.install_aliases() |
| 8 | +from future.utils import raise_from |
8 | 9 | from builtins import next |
9 | 10 | from pickle import dumps, loads |
10 | 11 | import inspect |
@@ -90,14 +91,14 @@ def create_function_from_source(function_source, imports=None): |
90 | 91 | import_keys = list(ns.keys()) |
91 | 92 | exec(function_source, ns) |
92 | 93 |
|
93 | | - except Exception as msg: |
94 | | - msg = str(msg) + '\nError executing function:\n %s\n' % function_source |
| 94 | + except Exception as e: |
| 95 | + msg = '\nError executing function:\n %s\n' % function_source |
95 | 96 | msg += '\n'.join(["Functions in connection strings have to be standalone.", |
96 | 97 | "They cannot be declared either interactively or inside", |
97 | 98 | "another function or inline in the connect string. Any", |
98 | 99 | "imports should be done inside the function" |
99 | 100 | ]) |
100 | | - raise RuntimeError(msg) |
| 101 | + raise_from(RuntimeError(msg), e) |
101 | 102 | ns_funcs = list(set(ns) - set(import_keys + ['__builtins__'])) |
102 | 103 | assert len(ns_funcs) == 1, "Function or inputs are ill-defined" |
103 | 104 | funcname = ns_funcs[0] |
@@ -199,14 +200,14 @@ def package_check(pkg_name, version=None, app=None, checker=LooseVersion, |
199 | 200 | msg += ' with version >= %s' % (version,) |
200 | 201 | try: |
201 | 202 | mod = __import__(pkg_name) |
202 | | - except ImportError: |
203 | | - raise exc_failed_import(msg) |
| 203 | + except ImportError as e: |
| 204 | + raise_from(exc_failed_import(msg), e) |
204 | 205 | if not version: |
205 | 206 | return |
206 | 207 | try: |
207 | 208 | have_version = mod.__version__ |
208 | | - except AttributeError: |
209 | | - raise exc_failed_check('Cannot find version for %s' % pkg_name) |
| 209 | + except AttributeError as e: |
| 210 | + raise_from(exc_failed_check('Cannot find version for %s' % pkg_name), e) |
210 | 211 | if checker(have_version) < checker(version): |
211 | 212 | raise exc_failed_check(msg) |
212 | 213 |
|
|
0 commit comments