Skip to content

Commit 4280e49

Browse files
authored
Merge pull request #217 from bfredl/error
nvim: show errors in handler on stderr when used as client
2 parents 4f9d930 + 861b0ba commit 4280e49

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

neovim/api/buffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def add_highlight(self, hl_group, line, col_start=0,
125125
line, col_start, col_end, async=async)
126126

127127
def clear_highlight(self, src_id, line_start=0, line_end=-1, async=True):
128-
"""clear highlights from the buffer."""
128+
"""Clear highlights from the buffer."""
129129
self.request('buffer_clear_highlight', src_id,
130130
line_start, line_end, async=async)
131131

neovim/api/nvim.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,32 @@ def run_loop(self, request_cb, notification_cb,
146146
This should not be called from a plugin running in the host, which
147147
already runs the loop and dispatches events to plugins.
148148
"""
149+
if err_cb is None:
150+
err_cb = sys.stderr.write
151+
self._err_cb = err_cb
152+
149153
def filter_request_cb(name, args):
154+
name = self._from_nvim(name)
150155
args = walk(self._from_nvim, args)
151-
result = request_cb(self._from_nvim(name), args)
156+
try:
157+
result = request_cb(name, args)
158+
except Exception:
159+
msg = ("error caught in request handler '{} {}'\n{}\n\n"
160+
.format(name, args, format_exc_skip(1, 5)))
161+
self._err_cb(msg)
162+
raise
152163
return walk(self._to_nvim, result)
153164

154165
def filter_notification_cb(name, args):
155-
notification_cb(self._from_nvim(name), walk(self._from_nvim, args))
156-
157-
if err_cb is None:
158-
err_cb = sys.stderr.write
159-
self._err_cb = err_cb
166+
name = self._from_nvim(name)
167+
args = walk(self._from_nvim, args)
168+
try:
169+
notification_cb(name, args)
170+
except Exception:
171+
msg = ("error caught in notification handler '{} {}'\n{}\n\n"
172+
.format(name, args, format_exc_skip(1, 5)))
173+
self._err_cb(msg)
174+
raise
160175

161176
self._session.run(filter_request_cb, filter_notification_cb, setup_cb)
162177

neovim/plugin/host.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def _wrap_function(self, fn, sync, decode, nvim_bind, name, *args):
7777
msg = ("error caught in async handler '{} {}'\n{}\n"
7878
.format(name, args, format_exc_skip(1, 5)))
7979
self._on_async_err(msg + "\n")
80-
raise
8180

8281
def _on_request(self, name, args):
8382
"""Handle a msgpack-rpc request."""

0 commit comments

Comments
 (0)