@@ -38,7 +38,9 @@ def __init__(self, nvim):
3838 self ._specs = {}
3939 self ._loaded = {}
4040 self ._load_errors = {}
41- self ._notification_handlers = {}
41+ self ._notification_handlers = {
42+ 'nvim_error_event' : self ._on_error_event
43+ }
4244 self ._request_handlers = {
4345 'poll' : lambda : 'ok' ,
4446 'specs' : self ._on_specs_request ,
@@ -49,8 +51,16 @@ def __init__(self, nvim):
4951 self ._decode_default = IS_PYTHON3
5052
5153 def _on_async_err (self , msg ):
54+ # uncaught python exception
5255 self .nvim .err_write (msg , async_ = True )
5356
57+ def _on_error_event (self , kind , msg ):
58+ # error from nvim due to async request
59+ # like nvim.command(..., async_=True)
60+ errmsg = "{}: Async request caused an error:\n {}\n " .format (
61+ self .name , decode_if_bytes (msg ))
62+ self .nvim .err_write (errmsg , async_ = True )
63+
5464 def start (self , plugins ):
5565 """Start listening for msgpack-rpc requests and notifications."""
5666 self .nvim .run_loop (self ._on_request ,
@@ -153,6 +163,7 @@ def _load(self, plugins):
153163 name = "python{}-{}-host" .format (sys .version_info [0 ], kind )
154164 attributes = {"license" : "Apache v2" ,
155165 "website" : "github.com/neovim/pynvim" }
166+ self .name = name
156167 self .nvim .api .set_client_info (
157168 name , VERSION .__dict__ , "host" , host_method_spec ,
158169 attributes , async_ = True )
0 commit comments