mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
channel: Extract function for sending errors that are not responses
This commit is contained in:
parent
c8297e462a
commit
c0b0bd07fd
@ -207,12 +207,12 @@ static void parse_msgpack(RStream *rstream, void *data, bool eof)
|
||||
msgpack_unpacked unpacked;
|
||||
msgpack_unpacked_init(&unpacked);
|
||||
UnpackResult result;
|
||||
msgpack_packer response;
|
||||
|
||||
// Deserialize everything we can.
|
||||
while ((result = msgpack_rpc_unpack(channel->unpacker, &unpacked))
|
||||
== kUnpackResultOk) {
|
||||
// Each object is a new msgpack-rpc request and requires an empty response
|
||||
msgpack_packer response;
|
||||
msgpack_packer_init(&response, channel->sbuffer, msgpack_sbuffer_write);
|
||||
// Perform the call
|
||||
msgpack_rpc_call(channel->id, &unpacked.data, &response);
|
||||
@ -234,26 +234,37 @@ static void parse_msgpack(RStream *rstream, void *data, bool eof)
|
||||
// A not so uncommon cause for this might be deserializing objects with
|
||||
// a high nesting level: msgpack will break when it's internal parse stack
|
||||
// size exceeds MSGPACK_EMBED_STACK_SIZE(defined as 32 by default)
|
||||
msgpack_packer_init(&response, channel->sbuffer, msgpack_sbuffer_write);
|
||||
msgpack_pack_array(&response, 4);
|
||||
msgpack_pack_int(&response, 1);
|
||||
msgpack_pack_int(&response, 0);
|
||||
msgpack_rpc_error("Invalid msgpack payload. "
|
||||
"This error can also happen when deserializing "
|
||||
"an object with high level of nesting",
|
||||
&response);
|
||||
WBuffer *buffer = wstream_new_buffer(xmemdup(channel->sbuffer->data,
|
||||
channel->sbuffer->size),
|
||||
channel->sbuffer->size,
|
||||
free);
|
||||
if (!channel_write(channel, buffer)) {
|
||||
return;
|
||||
}
|
||||
// Clear the buffer for future calls
|
||||
msgpack_sbuffer_clear(channel->sbuffer);
|
||||
send_error(channel, "Invalid msgpack payload. "
|
||||
"This error can also happen when deserializing "
|
||||
"an object with high level of nesting");
|
||||
}
|
||||
}
|
||||
|
||||
static void send_error(Channel *channel, char *msg)
|
||||
{
|
||||
msgpack_packer err;
|
||||
// See src/msgpack/unpack_template.h in msgpack source tree for
|
||||
// causes for this error(search for 'goto _failed')
|
||||
//
|
||||
// A not so uncommon cause for this might be deserializing objects with
|
||||
// a high nesting level: msgpack will break when it's internal parse stack
|
||||
// size exceeds MSGPACK_EMBED_STACK_SIZE(defined as 32 by default)
|
||||
msgpack_packer_init(&err, channel->sbuffer, msgpack_sbuffer_write);
|
||||
msgpack_pack_array(&err, 4);
|
||||
msgpack_pack_int(&err, 1);
|
||||
msgpack_pack_int(&err, 0);
|
||||
msgpack_rpc_error(msg, &err);
|
||||
WBuffer *buffer = wstream_new_buffer(xmemdup(channel->sbuffer->data,
|
||||
channel->sbuffer->size),
|
||||
channel->sbuffer->size,
|
||||
free);
|
||||
if (!channel_write(channel, buffer)) {
|
||||
return;
|
||||
}
|
||||
// Clear the buffer for future calls
|
||||
msgpack_sbuffer_clear(channel->sbuffer);
|
||||
}
|
||||
|
||||
static bool channel_write(Channel *channel, WBuffer *buffer)
|
||||
{
|
||||
bool success;
|
||||
|
Loading…
Reference in New Issue
Block a user