print snippet information in backtrace (fix #551)
This commit is contained in:
parent
d03b13a684
commit
698f2d4910
@ -6,6 +6,7 @@
|
||||
import re
|
||||
|
||||
import vim
|
||||
import textwrap
|
||||
|
||||
from UltiSnips import _vim
|
||||
from UltiSnips.compatibility import as_unicode
|
||||
@ -116,7 +117,29 @@ class SnippetDefinition(object):
|
||||
|
||||
snip = SnippetUtilForAction(locals)
|
||||
|
||||
exec(code, {'snip': snip})
|
||||
try:
|
||||
exec(code, {'snip': snip})
|
||||
except Exception as e:
|
||||
e.snippet_info = textwrap.dedent("""
|
||||
Trigger: {}
|
||||
Description: {}
|
||||
Context: {}
|
||||
Pre-expand: {}
|
||||
Post-expand: {}
|
||||
""").format(
|
||||
self._trigger,
|
||||
self._description,
|
||||
self._context_code if self._context_code else '<none>',
|
||||
self._actions['pre_expand'] if 'pre_expand' in self._actions
|
||||
else '<none>',
|
||||
self._actions['post_expand'] if 'post_expand' in self._actions
|
||||
else '<none>',
|
||||
code,
|
||||
)
|
||||
|
||||
e.snippet_code = code
|
||||
|
||||
raise
|
||||
|
||||
return snip
|
||||
|
||||
|
@ -10,6 +10,7 @@ import platform
|
||||
import traceback
|
||||
import sys
|
||||
import vim
|
||||
import re
|
||||
from contextlib import contextmanager
|
||||
|
||||
from UltiSnips import _vim
|
||||
@ -68,6 +69,11 @@ Following is the full stack trace:
|
||||
"""
|
||||
|
||||
msg += traceback.format_exc()
|
||||
if hasattr(e, 'snippet_info'):
|
||||
msg += "\nSnippet, caused error:\n"
|
||||
msg += re.sub(
|
||||
'^(?=\S)', ' ', e.snippet_info, flags=re.MULTILINE
|
||||
)
|
||||
# snippet_code comes from _python_code.py, it's set manually for
|
||||
# providing error message with stacktrace of failed python code
|
||||
# inside of the snippet.
|
||||
|
@ -263,3 +263,44 @@ class ParseSnippets_PrintPythonStacktraceMultiline(_VimTest):
|
||||
wanted = keys
|
||||
expected_error = " > \s+qwe"
|
||||
|
||||
|
||||
class ParseSnippets_PrintErroneousSnippet(_VimTest):
|
||||
files = { 'us/all.snippets': r"""
|
||||
snippet test "asd()" e
|
||||
endsnippet
|
||||
"""}
|
||||
keys = 'test' + EX
|
||||
wanted = keys
|
||||
expected_error = "Trigger: test"
|
||||
|
||||
|
||||
class ParseSnippets_PrintErroneousSnippetContext(_VimTest):
|
||||
files = { 'us/all.snippets': r"""
|
||||
snippet test "asd()" e
|
||||
endsnippet
|
||||
"""}
|
||||
keys = 'test' + EX
|
||||
wanted = keys
|
||||
expected_error = "Context: asd"
|
||||
|
||||
|
||||
class ParseSnippets_PrintErroneousSnippetPreAction(_VimTest):
|
||||
files = { 'us/all.snippets': r"""
|
||||
pre_expand "asd()"
|
||||
snippet test
|
||||
endsnippet
|
||||
"""}
|
||||
keys = 'test' + EX
|
||||
wanted = keys
|
||||
expected_error = "Pre-expand: asd"
|
||||
|
||||
|
||||
class ParseSnippets_PrintErroneousSnippetPostAction(_VimTest):
|
||||
files = { 'us/all.snippets': r"""
|
||||
post_expand "asd()"
|
||||
snippet test
|
||||
endsnippet
|
||||
"""}
|
||||
keys = 'test' + EX
|
||||
wanted = keys
|
||||
expected_error = "Post-expand: asd"
|
||||
|
Loading…
Reference in New Issue
Block a user