New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exceptions in load_extensions #1337

Closed
wants to merge 2 commits into
base: develop
from

Conversation

2 participants
@blueyed
Contributor

blueyed commented Nov 28, 2015

This will skip those extensions, instead of crashing mopidy, e.g. when
mopidy-mopify fails because of a missing HOME environment variable
during mopidy's tests.
Ref: dirkgroenen/mopidy-mopify#119

Please note that the error will not show up with --help, because the logging is not setup then yet.

Handle exceptions in load_extensions
This will skip those extensions, instead of crashing mopidy, e.g. when
mopidy-mopify fails because of a missing HOME environment variable
during mopidy's tests.
Ref: dirkgroenen/mopidy-mopify#119
@blueyed

This comment has been minimized.

Contributor

blueyed commented Nov 28, 2015

Some more information of the crash during test_help_has_mopidy_options:

({u'PYTHONPATH': u'…/mopidy/mopidy/..:'}, ['…/mopidy/.tox/py27/bin/python2.7', '…/mopidy/mopidy', u'--help'])

Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "…/mopidy/mopidy/__main__.py", line 239, in <module>
    sys.exit(main())
  File "…/mopidy/mopidy/__main__.py", line 69, in main
    extensions_data = ext.load_extensions()
  File "…/mopidy/mopidy/ext.py", line 201, in load_extensions
    extension_class = entry_point.load(require=False)
  File "…/mopidy/.tox/py27/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
    return self.resolve()
  File "…/mopidy/.tox/py27/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/site-packages/mopidy_mopify/__init__.py", line 9, in <module>
    from services.sync import sync
  File "/usr/lib/python2.7/site-packages/mopidy_mopify/services/sync/sync.py", line 9, in <module>
    class Sync(object):
  File "/usr/lib/python2.7/site-packages/mopidy_mopify/services/sync/sync.py", line 16, in Sync
    syncfile = os.path.join(userhome, directory, filename)
  File "…/mopidy/.tox/py27/lib/python2.7/posixpath.py", line 70, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
except Exception as e:
logger.exception("Failed to load extension {}: {}".format(
entry_point.name, e
), exc_info=e)

This comment has been minimized.

@jodal

jodal Nov 28, 2015

Member

logger.exception() will get the exc_info itself without explicitly passing it since this is inside an except block.

This comment has been minimized.

@blueyed

blueyed Nov 28, 2015

Contributor

OK, will change it.

try:
extension_class = entry_point.load(require=False)
except Exception as e:
logger.exception("Failed to load extension {}: {}".format(

This comment has been minimized.

@jodal

jodal Nov 28, 2015

Member

I don't think we have a single other occurrence of .format() in our source. We use old style formatting with %.

This comment has been minimized.

@blueyed

blueyed Nov 28, 2015

Contributor

It's used in mopidy/internal/validation.py, but I will change it.

@jodal

This comment has been minimized.

Member

jodal commented Nov 28, 2015

I'm positive to just logging the stack trace and continuing if an extension crashes during setup. All the debug information we used to have will still be available, and Mopidy remains usable, probably causing less bugs reported on Mopidy core.

@jodal jodal self-assigned this Nov 28, 2015

@jodal jodal added this to the v1.2 - Gapless milestone Nov 28, 2015

@blueyed

This comment has been minimized.

Contributor

blueyed commented Nov 28, 2015

Pushed a fixup-commit.
That should be squashed before/when merging.
Let me know if/when I should do it.

@jodal

This comment has been minimized.

Member

jodal commented Nov 28, 2015

Squashed and merged in b3ec02d.

Thanks! :-)

@jodal jodal closed this Nov 28, 2015

@blueyed blueyed deleted the blueyed:handle-exception-in-extensions branch Nov 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment