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) { } catch (std::invalid_argument& e) {
// *message is partially deserialized but some field (e.g. |id|) are likely // *message is partially deserialized but some field (e.g. |id|) are likely
// available. // available.
return std::string("Unable to deserialize request '") + method + "' " + return std::string("Fail to parse '") + method + "' " +
static_cast<JsonReader&>(visitor).GetPath() + " " + e.what(); 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. // Use "0" to indicate any element for now.
path_.push_back("0"); path_.push_back("0");
for (auto& entry : m_->GetArray()) { for (auto& entry : m_->GetArray()) {
JsonReader sub(&entry); auto saved = m_;
fn(sub); m_ = &entry;
fn(*this);
m_ = saved;
} }
path_.pop_back(); path_.pop_back();
} }
@ -53,8 +55,10 @@ class JsonReader : public Reader {
path_.push_back(name); path_.push_back(name);
auto it = m_->FindMember(name); auto it = m_->FindMember(name);
if (it != m_->MemberEnd()) { if (it != m_->MemberEnd()) {
JsonReader sub(&it->value); auto saved = m_;
fn(sub); m_ = &it->value;
fn(*this);
m_ = saved;
} }
path_.pop_back(); path_.pop_back();
} }