AssertionError hiding my mistake
See original GitHub issueI accidentally returned an internal type instead of a str from my custom completer and got this exception:
Traceback (most recent call last):
File "doc_prompt_toolkit.py", line 25, in <module>
text = prompt('Column', completer=completer, bottom_toolbar='. to see shortcuts, ( to see constructor arguments')
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 803, in prompt
return session.prompt(*a, **kw)
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 731, in prompt
return run_sync()
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 715, in run_sync
return self.app.run(inputhook=self.inputhook, pre_run=pre_run)
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/application/application.py", line 682, in run
return run()
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/application/application.py", line 656, in run
return f.result()
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/eventloop/future.py", line 149, in result
raise self._exception
AssertionError
The original assertion error stack trace is lost. So I fiddled with the code and made it not catch this exception and store it and then I got:
Traceback (most recent call last):
File "doc_prompt_toolkit.py", line 27, in <module>
text = prompt('Column', completer=completer, bottom_toolbar='. to see shortcuts, ( to see constructor arguments')
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 803, in prompt
return session.prompt(*a, **kw)
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 731, in prompt
return run_sync()
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 715, in run_sync
return self.app.run(inputhook=self.inputhook, pre_run=pre_run)
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/application/application.py", line 682, in run
return run()
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/application/application.py", line 654, in run
f = self.run_async(pre_run=pre_run)
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/application/application.py", line 640, in run_async
return ensure_future(_run_async2())
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 21, in ensure_future
return _run_coroutine(future_or_coroutine)
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 115, in _run_coroutine
step_next()
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 104, in step_next
ref.future.set_exception(e)
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 86, in step_next
new_f = coroutine.send(None)
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/application/application.py", line 637, in _run_async2
assert not self._is_running
AssertionError
This isn’t very helpful either, the original exception is still gone! So I commented out this assertion and then I got the real error:
File "/Users/andersh/Projects/tri.table/venv/lib/python2.7/site-packages/prompt_toolkit/formatted_text/base.py", line 50, in to_formatted_text
'HTML, ANSI or a FormattedText instance. Got %r' % value)
ValueError: No formatted text. Expecting a unicode object, HTML, ANSI or a FormattedText instance. Got 'Column'
That error message is very helpful but it was very hard to get to it. It would have been better to print that exception and stack trace and directly doing exit(1) for example.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Getting Assertion Error when training data in neural network in ...
In newff function the range i decide based on Min/Max but i dont know how to decide the other parameters. How much hidden...
Read more >save_facebook_model() - AssertionError · Issue #2853 - GitHub
I tried with a model with a vocabulary of 4500 and it worked. So I guess there is a limitation in that. But...
Read more >Exception Handling & Assertion in Java
If it is not true, the JVM will throw an AssertionError . This error signals you that you have an invalid assumption that...
Read more >1838452 – python-black fails to build with Python 3.9
Bug 1838452 - python-black fails to build with Python 3.9: INTERNAL ERROR: Black produced code that is not equivalent to the source.
Read more >Assertion error? [Archive] - Avid Pro Audio Community
When a popup screen appeared with the words "assertion error" followed by text and ... is an inferiority complex hiding behind a superiority...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @boxed,
In Python 3, all the exceptions are chained and will be printed. For Python 2, you can disable the assertions by passing the
-O
option to the Python interpreter.I think that the object that you have there is a
str
in Python 2 instead of aunicode
object. Maybe try to use eitherfrom __future__ import unicode_literals
, or prefix'Column'
with au
:u'Column'
.Closing this. Feel free to open again if needed.