API: validation: mention invalid method name (#8489)

This commit is contained in:
Justin M. Keyes
2018-06-07 10:56:44 +02:00
committed by GitHub
parent 5a82afa17a
commit 3abf17ae88
7 changed files with 37 additions and 11 deletions

View File

@@ -312,24 +312,30 @@ static void handle_request(Channel *channel, msgpack_object *request)
api_clear_error(&error);
return;
}
// Retrieve the request handler
MsgpackRpcRequestHandler handler;
Array args = ARRAY_DICT_INIT;
msgpack_object *method = msgpack_rpc_method(request);
if (method) {
handler = msgpack_rpc_get_handler_for(method->via.bin.ptr,
method->via.bin.size);
if (handler.fn == msgpack_rpc_handle_missing_method) {
String m = method->via.bin.size > 0
? cbuf_to_string(method->via.bin.ptr, method->via.bin.size)
: cstr_to_string("<empty>");
ADD(args, STRING_OBJ(m));
handler.async = true;
} else if (!msgpack_rpc_to_array(msgpack_rpc_args(request), &args)) {
handler.fn = msgpack_rpc_handle_invalid_arguments;
handler.async = true;
}
} else {
handler.fn = msgpack_rpc_handle_missing_method;
handler.async = true;
}
Array args = ARRAY_DICT_INIT;
if (!msgpack_rpc_to_array(msgpack_rpc_args(request), &args)) {
handler.fn = msgpack_rpc_handle_invalid_arguments;
handler.async = true;
}
RequestEvent *evdata = xmalloc(sizeof(RequestEvent));
evdata->channel = channel;
evdata->handler = handler;

View File

@@ -493,7 +493,8 @@ Object msgpack_rpc_handle_missing_method(uint64_t channel_id,
Array args,
Error *error)
{
api_set_error(error, kErrorTypeException, "Invalid method name");
api_set_error(error, kErrorTypeException, "Invalid method: %s",
args.size > 0 ? args.items[0].data.string.data : "?");
return NIL;
}