Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit e343477

Browse files
committed
msgpack_rpc_stream: provide context for invalid data
1 parent e3ba2e3 commit e343477

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

nvim/msgpack_rpc_stream.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ MsgpackRpcStream.__index = MsgpackRpcStream
6464
function MsgpackRpcStream.new(stream)
6565
return setmetatable({
6666
_stream = stream,
67+
_previous_chunk = nil,
6768
_pack = mpack.Packer({
6869
ext = {
6970
[Buffer] = function(o) return 0, mpack.pack(o.id) end,
@@ -120,16 +121,19 @@ function MsgpackRpcStream:read_start(request_cb, notification_cb, eof_cb)
120121

121122
print(string.format("Error deserialising msgpack data stream at pos %d:\n%s\n",
122123
oldpos, printable))
124+
print(string.format("... occurred after %s", self._previous_chunk))
123125
error(type)
124126
end
125127
if type == 'request' or type == 'notification' then
128+
self._previous_chunk = string.format('%s<%s>', type, method_or_error)
126129
if type == 'request' then
127130
request_cb(method_or_error, args_or_result, Response.new(self,
128131
id_or_cb))
129132
else
130133
notification_cb(method_or_error, args_or_result)
131134
end
132135
elseif type == 'response' then
136+
self._previous_chunk = string.format('response<%s,%s>', id_or_cb, args_or_result)
133137
if method_or_error == mpack.NIL then
134138
method_or_error = nil
135139
else

0 commit comments

Comments
 (0)