question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: exceptions are swallowed by __exit__

See original GitHub issue

Description

By returning a truthy value from __exit__, exceptions thrown when using Halo as a context manager are swallowed, and execution continues.

System settings

  • Python version: 3.6
  • Halo version: 0.0.18

Expected behaviour

✖ Doing the thing ...
Traceback (most recent call last):
  File "example.py", line 1337, in example
    raise Exception('stuff')
Exception: stuff

Steps to recreate

from halo import Halo

with Halo('Doing the thing ... '):
    # No exception seen
    raise Exception('stuff')
from halo import Halo

class TransparentHalo(Halo):
    def __exit__(self, exc_type, exc_value, traceback):
        super().__exit__(exc_type, exc_value, traceback)
        # no return

with TransparentHalo('Doing the thing ... '):
    raise Exception('stuff')

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
toejoughcommented, Oct 23, 2018

just encountered this myself. if anyone is unclear how to move forward in the meantime, here’s a quick shim:

import contextlib

@contextlib.contextmanager
def halo_shim(text):
    spinner = halo.Halo(text)
    spinner.start()
    try:
        yield spinner
    finally:
        spinner.stop()
1reaction
theY4Kmancommented, Oct 21, 2018

Aww yiss! That did it! Thank you 😃 The linter fails with this guy I haven’t had time to diagnose, yet, but with an interesting traceback like that, I’m dying to know what the hell it’s doing

lint recreate: /Users/they4kman/programming/third-party/halo/.tox/lint
lint installdeps: -r/Users/they4kman/programming/third-party/halo/requirements.txt, -r/Users/they4kman/programming/third-party/halo/requirements-dev.txt
lint inst: /Users/they4kman/programming/third-party/halo/.tox/dist/halo-0.0.18.zip
lint installed: appnope==0.1.0,astroid==2.0.4,bleach==3.0.2,colorama==0.3.9,coverage==4.4.1,cursor==1.2.0,decorator==4.3.0,defusedxml==0.5.0,entrypoints==0.2.3,enum34==1.1.6,halo==0.0.18,ipykernel==5.1.0,ipython==5.7.0,ipython-genutils==0.2.0,ipywidgets==7.1.0,isort==4.3.4,Jinja2==2.10,jsonschema==2.6.0,jupyter-client==5.2.3,jupyter-core==4.4.0,lazy-object-proxy==1.3.1,log-symbols==0.0.11,MarkupSafe==1.0,mccabe==0.6.1,mistune==0.8.4,nbconvert==5.4.0,nbformat==4.4.0,nose==1.3.7,notebook==5.7.0,pandocfilters==1.4.2,pexpect==4.6.0,pickleshare==0.7.5,pluggy==0.8.0,prometheus-client==0.4.2,prompt-toolkit==1.0.15,ptyprocess==0.6.0,py==1.7.0,Pygments==2.2.0,pylint==1.7.2,python-dateutil==2.7.3,pyzmq==17.1.2,Send2Trash==1.5.0,simplegeneric==0.8.1,six==1.11.0,spinners==0.0.23,termcolor==1.1.0,terminado==0.8.1,testpath==0.4.2,tornado==5.1.1,tox==2.8.2,traitlets==4.3.2,virtualenv==16.0.0,wcwidth==0.1.7,webencodings==0.5.1,widgetsnbextension==3.1.4,wrapt==1.10.11
lint runtests: PYTHONHASHSEED='3195813463'
lint runtests: commands[0] | pylint --errors-only --rcfile=/Users/they4kman/programming/third-party/halo/.pylintrc --output-format=colorized halo
Traceback (most recent call last):
  File "/Users/they4kman/programming/third-party/halo/.tox/lint/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/Users/they4kman/programming/third-party/halo/.tox/lint/lib/python3.7/site-packages/pylint/__init__.py", line 13, in run_pylint
    Run(sys.argv[1:])
  File "/Users/they4kman/programming/third-party/halo/.tox/lint/lib/python3.7/site-packages/pylint/lint.py", line 1260, in __init__
    'init-hook')))
  File "/Users/they4kman/programming/third-party/halo/.tox/lint/lib/python3.7/site-packages/pylint/lint.py", line 1361, in cb_init_hook
    exec(value) # pylint: disable=exec-used
  File "<string>", line 8
    ZGljdChfX2ZpbGVfXz1hY3RpdmF0ZV90aGlzKSkK'.decode('base64')
                                            ^
SyntaxError: invalid syntax
ERROR: InvocationError: '/Users/they4kman/programming/third-party/halo/.tox/lint/bin/pylint --errors-only --rcfile=/Users/they4kman/programming/third-party/halo/.pylintrc --output-format=colorized halo'

It’s been a volcano at work for a hot minute — I’m hoping it’ll die down, and I’ll have Happy Fun Free Time™ again. I dig your motives, and you’ve been hella helpful; I’d love to contribute back.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors after test completion are swallowed #3226 - GitHub
Actual behavior: Tests pass, Mocha exits with code zero. error after test complete ✓ sync ✓ promise ✓ callback 3 passing (16ms).
Read more >
Do Not Swallow The Exceptions | Justin James
However this is my least favorite way to not swallow exception as you are still technically swallowing the error but you can at...
Read more >
Stopping Twisted from swallowing exceptions - Stack Overflow
Python had a known behavior for uncaught exceptions. They end the process. Any library that changes this behavior is absolutely swallowing the exception....
Read more >
507855 – Exceptions being swallowed in DSF - Bugs - Eclipse
I have marked the cases where the exceptions are not being swallowed (18) in the gerrit instead. Rather than rewrite all 100+ locations...
Read more >
10 Python Exception Handling Best Practices - CLIMB
Finally, swallowing exceptions is generally considered bad practice because it goes against the principle of “fail early, fail often.” Failing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found