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

Commit e3ba2e3

Browse files
committed
msgpack_rpc_stream: additional debug output for failed unpack
1 parent c9763be commit e3ba2e3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

nvim/msgpack_rpc_stream.lua

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,27 @@ function MsgpackRpcStream:read_start(request_cb, notification_cb, eof_cb)
101101
if not data then
102102
return eof_cb()
103103
end
104-
local type, id_or_cb
104+
local status, type, id_or_cb
105105
local pos = 1
106106
local len = #data
107107
while pos <= len do
108-
type, id_or_cb, method_or_error, args_or_result, pos =
109-
self._session:receive(data, pos)
108+
-- grab a copy of pos since pcall() will set it to nil on error
109+
local oldpos = pos
110+
status, type, id_or_cb, method_or_error, args_or_result, pos = pcall(
111+
self._session.receive, self._session, data, pos)
112+
if not status then
113+
-- write the full blob of bad data to a specific file
114+
local outfile = io.open('./msgpack-invalid-data', 'w')
115+
outfile:write(data)
116+
outfile:close()
117+
118+
-- build a printable representation of the bad part of the string
119+
local printable = hexdump(data:sub(oldpos, oldpos + 8 * 10))
120+
121+
print(string.format("Error deserialising msgpack data stream at pos %d:\n%s\n",
122+
oldpos, printable))
123+
error(type)
124+
end
110125
if type == 'request' or type == 'notification' then
111126
if type == 'request' then
112127
request_cb(method_or_error, args_or_result, Response.new(self,

0 commit comments

Comments
 (0)