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

Commit

Permalink
msgpack_rpc_stream: provide context for invalid data
Browse files Browse the repository at this point in the history
  • Loading branch information
phodge committed Jul 9, 2018
1 parent e3ba2e3 commit e343477
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nvim/msgpack_rpc_stream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ MsgpackRpcStream.__index = MsgpackRpcStream
function MsgpackRpcStream.new(stream)
return setmetatable({
_stream = stream,
_previous_chunk = nil,
_pack = mpack.Packer({
ext = {
[Buffer] = function(o) return 0, mpack.pack(o.id) end,
Expand Down Expand Up @@ -120,16 +121,19 @@ function MsgpackRpcStream:read_start(request_cb, notification_cb, eof_cb)

print(string.format("Error deserialising msgpack data stream at pos %d:\n%s\n",
oldpos, printable))
print(string.format("... occurred after %s", self._previous_chunk))
error(type)
end
if type == 'request' or type == 'notification' then
self._previous_chunk = string.format('%s<%s>', type, method_or_error)
if type == 'request' then
request_cb(method_or_error, args_or_result, Response.new(self,
id_or_cb))
else
notification_cb(method_or_error, args_or_result)
end
elseif type == 'response' then
self._previous_chunk = string.format('response<%s,%s>', id_or_cb, args_or_result)
if method_or_error == mpack.NIL then
method_or_error = nil
else
Expand Down

0 comments on commit e343477

Please sign in to comment.