Skip to content

Commit 5b50ce9

Browse files
committed
host: set self.name for _on_error_event
fix #425
1 parent 87724dd commit 5b50ce9

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

pynvim/plugin/host.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def _on_error_event(self, kind, msg):
5959
errmsg = "{}: Async request caused an error:\n{}\n".format(
6060
self.name, decode_if_bytes(msg))
6161
self.nvim.err_write(errmsg, async_=True)
62+
return errmsg
6263

6364
def start(self, plugins):
6465
"""Start listening for msgpack-rpc requests and notifications."""
@@ -177,9 +178,9 @@ def _load(self, plugins):
177178

178179
kind = ("script-host" if len(plugins) == 1 and has_script
179180
else "rplugin-host")
180-
self.nvim.api.set_client_info(
181-
*get_client_info(kind, 'host', host_method_spec),
182-
async_=True)
181+
info = get_client_info(kind, 'host', host_method_spec)
182+
self.name = info[0]
183+
self.nvim.api.set_client_info(*info, async_=True)
183184

184185
def _unload(self):
185186
for path, plugin in self._loaded.items():

test/test_events.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def test_sending_notify(vim):
2828
assert vim.eval('g:data') == 'xyz'
2929

3030

31+
def test_async_error(vim):
32+
# Invoke a bogus Ex command via notify (async).
33+
vim.command("lolwut", async_=True)
34+
event = vim.next_message()
35+
assert event[1] == 'nvim_error_event'
36+
37+
3138
def test_broadcast(vim):
3239
vim.subscribe('event2')
3340
vim.command('call rpcnotify(0, "event1", 1, 2, 3)')

test/test_host.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ def test_host_clientinfo(vim):
99
assert 'remote' == vim.api.get_chan_info(vim.channel_id)['client']['type']
1010
h._load([])
1111
assert 'host' == vim.api.get_chan_info(vim.channel_id)['client']['type']
12+
13+
14+
# Smoke test for Host._on_error_event(). #425
15+
def test_host_async_error(vim):
16+
h = Host(vim)
17+
h._load([])
18+
# Invoke a bogus Ex command via notify (async).
19+
vim.command("lolwut", async_=True)
20+
event = vim.next_message()
21+
assert event[1] == 'nvim_error_event'
22+
assert 'rplugin-host: Async request caused an error:\nboom\n' \
23+
in h._on_error_event(None, 'boom')

test/test_vim.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_cwd(vim, tmpdir):
226226
return a.nvim_buf_line_count(buf)
227227
end
228228
229-
pynvimtest = {setbuf=setbuf,getbuf=getbuf}
229+
pynvimtest = {setbuf=setbuf, getbuf=getbuf}
230230
231231
return "eggspam"
232232
"""
@@ -235,7 +235,7 @@ def test_cwd(vim, tmpdir):
235235
def test_lua(vim):
236236
assert vim.exec_lua(lua_code, 7) == "eggspam"
237237
assert vim.lua.pynvimtest_func(3) == 10
238-
testmod = vim.lua.pynvimtest
238+
lua_module = vim.lua.pynvimtest
239239
buf = vim.current.buffer
240-
testmod.setbuf(buf, ["a", "b", "c", "d"], async_=True)
241-
assert testmod.getbuf(buf) == 4
240+
lua_module.setbuf(buf, ["a", "b", "c", "d"], async_=True)
241+
assert lua_module.getbuf(buf) == 4

0 commit comments

Comments
 (0)