diff options
author | Scott Prager <splinterofchaos@gmail.com> | 2015-04-06 13:37:09 -0400 |
---|---|---|
committer | Scott Prager <splinterofchaos@gmail.com> | 2015-04-13 10:20:42 -0400 |
commit | 920e5905d8e8cbb6f83f8a2bda4645e1ef3f0d00 (patch) | |
tree | da6f15dd604dafd699a886808c5429901422aa42 | |
parent | 676133aa9b20923e387b77f95d5df55803a5842e (diff) | |
download | rneovim-920e5905d8e8cbb6f83f8a2bda4645e1ef3f0d00.tar.gz rneovim-920e5905d8e8cbb6f83f8a2bda4645e1ef3f0d00.tar.bz2 rneovim-920e5905d8e8cbb6f83f8a2bda4645e1ef3f0d00.zip |
channel: recognized nvim-style errors
-rw-r--r-- | src/nvim/msgpack_rpc/channel.c | 20 | ||||
-rw-r--r-- | test/functional/api/server_requests_spec.lua | 6 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 9c812ced82..b671b8b545 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -225,7 +225,25 @@ Object channel_send_call(uint64_t id, channel->pending_requests--; if (frame.errored) { - api_set_error(err, Exception, "%s", frame.result.data.string.data); + if (frame.result.type == kObjectTypeString) { + api_set_error(err, Exception, "%s", frame.result.data.string.data); + } else if (frame.result.type == kObjectTypeArray) { + // Should be an error in the form [type, message] + Array array = frame.result.data.array; + if (array.size == 2 && array.items[0].type == kObjectTypeInteger + && (array.items[0].data.integer == kErrorTypeException + || array.items[0].data.integer == kErrorTypeValidation) + && array.items[1].type == kObjectTypeString) { + err->type = (ErrorType) array.items[0].data.integer; + xstrlcpy(err->msg, array.items[1].data.string.data, sizeof(err->msg)); + err->set = true; + } else { + api_set_error(err, Exception, "%s", "unknown error"); + } + } else { + api_set_error(err, Exception, "%s", "unknown error"); + } + api_free_object(frame.result); } diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index a53fd8e006..34669c5f29 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -148,5 +148,11 @@ describe('server -> client', function() -- Call get_line_slice(buf, range [0,0], includes start, includes end) eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_line_slice', "..buf..", 0, 0, 1, 1)")) end) + + it('returns an error if the request failed', function() + local status, err = pcall(eval, "rpcrequest(vim, 'does-not-exist')") + eq(false, status) + eq(true, string.match(err, ': (.*)') == 'Failed to evaluate expression') + end) end) end) |