diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index 448daf8..da66033 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -57,7 +57,7 @@ def err_to_scratch_buffer(func): def wrapper(self, *args, **kwds): try: return func(self, *args, **kwds) - except: # pylint: disable=bare-except + except Exception as e: # pylint: disable=bare-except msg = \ """An error occured. This is either a bug in UltiSnips or a bug in a snippet definition. If you think this is a bug, please report it to @@ -65,7 +65,16 @@ https://github.com/SirVer/ultisnips/issues/new. Following is the full stack trace: """ + msg += traceback.format_exc() + if hasattr(e, 'code'): + msg += "\nFollowing is the full executed code:\n" + lines = e.code.split("\n") + number = 1 + for line in lines: + msg += str(number) + ": " + line + "\n" + number += 1 + # Vim sends no WinLeave msg here. self._leaving_buffer() # pylint:disable=protected-access _vim.new_scratch_buffer(msg) diff --git a/pythonx/UltiSnips/text_objects/_python_code.py b/pythonx/UltiSnips/text_objects/_python_code.py index 9427c01..3224681 100644 --- a/pythonx/UltiSnips/text_objects/_python_code.py +++ b/pythonx/UltiSnips/text_objects/_python_code.py @@ -266,8 +266,13 @@ class PythonCode(NoneditableTextObject): }) self._snip._reset(ct) # pylint:disable=protected-access + for code in self._codes: - exec(code, self._locals) # pylint:disable=exec-used + try: + exec(code, self._locals) # pylint:disable=exec-used + except Exception as e: + e.code = code + raise rv = as_unicode( self._snip.rv if self._snip._rv_changed # pylint:disable=protected-access