Skip to content

Commit 345b802

Browse files
committed
Improve error reporting when loading plugins
Don't throw exceptions, just log an error message and continue startup
1 parent cf3e5d7 commit 345b802

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

neovim/plugin/host.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, nvim):
3333
self._notification_handlers = {}
3434
self._request_handlers = {
3535
'poll': lambda: 'ok',
36-
'specs': lambda path: self._specs[path],
36+
'specs': lambda path: self._specs.get(path, []),
3737
'shutdown': self.shutdown
3838
}
3939
self._nvim_encoding = nvim.options['encoding']
@@ -81,23 +81,25 @@ def _on_notification(self, name, args):
8181
def _load(self, plugins):
8282
for path in plugins:
8383
if path in self._loaded:
84-
raise Exception('{0} is already loaded'.format(path))
84+
error('{0} is already loaded'.format(path))
85+
continue
8586
directory, name = os.path.split(os.path.splitext(path)[0])
8687
file, pathname, description = find_module(name, [directory])
88+
handlers = []
8789
try:
8890
module = imp.load_module(name, file, pathname, description)
89-
except ImportError:
90-
error('Encountered import error loading plugin at {0}'.format(
91-
path))
91+
self._discover_classes(module, handlers, path)
92+
self._discover_functions(module, handlers, path)
93+
if not handlers:
94+
error('{0} exports no handlers'.format(path))
95+
continue
96+
self._loaded[path] = {'handlers': handlers, 'module': module}
97+
except (ImportError, SyntaxError) as e:
98+
error(('Encountered import error loading '
99+
'plugin at {0}: {1}').format(path, e))
92100
except Exception as e:
93101
error('Error loading plugin at {0} {1}: {2}'.format(
94102
path, type(e).__name__, e))
95-
handlers = []
96-
self._discover_classes(module, handlers, path)
97-
self._discover_functions(module, handlers, path)
98-
if not handlers:
99-
raise Exception('{0} exports no handlers'.format(path))
100-
self._loaded[path] = {'handlers': handlers, 'module': module}
101103

102104
def _unload(self):
103105
for path, plugin in self._loaded.items():

0 commit comments

Comments
 (0)