Better error reporting in ResponseMessage

This commit is contained in:
Fangrui Song 2018-01-19 15:33:32 -08:00
parent 90c2a54bbc
commit 8f41aa72de
2 changed files with 10 additions and 6 deletions

View File

@ -162,8 +162,8 @@ optional<std::string> MessageRegistry::Parse(
} catch (std::invalid_argument& e) {
// *message is partially deserialized but some field (e.g. |id|) are likely
// available.
return std::string("Unable to deserialize request '") + method + "' " +
static_cast<JsonReader&>(visitor).GetPath() + " " + e.what();
return std::string("Fail to parse '") + method + "' " +
static_cast<JsonReader&>(visitor).GetPath() + ", expected " + e.what();
}
}

View File

@ -43,8 +43,10 @@ class JsonReader : public Reader {
// Use "0" to indicate any element for now.
path_.push_back("0");
for (auto& entry : m_->GetArray()) {
JsonReader sub(&entry);
fn(sub);
auto saved = m_;
m_ = &entry;
fn(*this);
m_ = saved;
}
path_.pop_back();
}
@ -53,8 +55,10 @@ class JsonReader : public Reader {
path_.push_back(name);
auto it = m_->FindMember(name);
if (it != m_->MemberEnd()) {
JsonReader sub(&it->value);
fn(sub);
auto saved = m_;
m_ = &it->value;
fn(*this);
m_ = saved;
}
path_.pop_back();
}