8000 Prevent third-party plugins with faulty hooks to crash the server · python-lsp/python-lsp-server@85a3e31 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85a3e31

Browse files
committed
Prevent third-party plugins with faulty hooks to crash the server
1 parent 6c5f44d commit 85a3e31

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pylsp/config/config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
DEFAULT_CONFIG_SOURCES = ['pycodestyle']
1717

1818

19+
class PluginManager(pluggy.PluginManager):
20+
21+
def _hookexec(self, hook, methods, kwargs):
22+
# Prevent faulty hooks to crash the server
23+
try:
24+
return self._inner_hookexec(hook, methods, kwargs)
25+
except Exception as e: # pylint: disable=broad-except
26+
log.warning(f"Failed to load hook {hook}: {e}")
27+
return []
28+
29+
1930
class Config:
2031
def __init__(self, root_uri, init_opts, process_id, capabilities):
2132
self._root_path = uris.to_fs_path(root_uri)
@@ -39,7 +50,7 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
3950
except ImportError:
4051
pass
4152

42-
self._pm = pluggy.PluginManager(PYLSP)
53+
self._pm = PluginManager(PYLSP)
4354
self._pm.trace.root.setwriter(log.debug)
4455
self._pm.enable_tracing()
4556
self._pm.add_hookspecs(hookspecs)

0 commit comments

Comments
 (0)
0