Disambiguate error messages in MethodCall
Reviewed By: fromcelticpark Differential Revision: D5706581 fbshipit-source-id: 06343e2a41d08a1594eb35bb96cc6dc7bf9e29c6
This commit is contained in:
parent
b8d347d113
commit
46f0a3b2f6
|
@ -13,6 +13,8 @@ namespace react {
|
|||
#define REQUEST_PARAMSS 2
|
||||
#define REQUEST_CALLID 3
|
||||
|
||||
static const char *errorPrefix = "Malformed calls from JS: ";
|
||||
|
||||
std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData) throw(std::invalid_argument) {
|
||||
if (jsonData.isNull()) {
|
||||
return {};
|
||||
|
@ -20,12 +22,12 @@ std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData) throw(std::i
|
|||
|
||||
if (!jsonData.isArray()) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("Did not get valid calls back from JS: ", jsonData.typeName()));
|
||||
folly::to<std::string>(errorPrefix, "input isn't array but ", jsonData.typeName()));
|
||||
}
|
||||
|
||||
if (jsonData.size() < REQUEST_PARAMSS + 1) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("Did not get valid calls back from JS: size == ", jsonData.size()));
|
||||
folly::to<std::string>(errorPrefix, "size == ", jsonData.size()));
|
||||
}
|
||||
|
||||
auto& moduleIds = jsonData[REQUEST_MODULE_IDS];
|
||||
|
@ -35,18 +37,18 @@ std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData) throw(std::i
|
|||
|
||||
if (!moduleIds.isArray() || !methodIds.isArray() || !params.isArray()) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("Did not get valid calls back from JS: ", folly::toJson(jsonData)));
|
||||
folly::to<std::string>(errorPrefix, "not all fields are arrays.\n\n", folly::toJson(jsonData)));
|
||||
}
|
||||
|
||||
if (moduleIds.size() != methodIds.size() || moduleIds.size() != params.size()) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("Did not get valid calls back from JS: ", folly::toJson(jsonData)));
|
||||
folly::to<std::string>(errorPrefix, "field sizes are different.\n\n", folly::toJson(jsonData)));
|
||||
}
|
||||
|
||||
if (jsonData.size() > REQUEST_CALLID) {
|
||||
if (!jsonData[REQUEST_CALLID].isNumber()) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("Did not get valid calls back from JS: %s", folly::toJson(jsonData)));
|
||||
folly::to<std::string>(errorPrefix, "invalid callId", jsonData[REQUEST_CALLID].typeName()));
|
||||
}
|
||||
callId = jsonData[REQUEST_CALLID].asInt();
|
||||
}
|
||||
|
@ -55,7 +57,7 @@ std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData) throw(std::i
|
|||
for (size_t i = 0; i < moduleIds.size(); i++) {
|
||||
if (!params[i].isArray()) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("Call argument isn't an array"));
|
||||
folly::to<std::string>(errorPrefix, "method arguments isn't array but ", params[i].typeName()));
|
||||
}
|
||||
|
||||
methodCalls.emplace_back(
|
||||
|
|
Loading…
Reference in New Issue