From 250fbab81843caabe045238b54e269211a571e16 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Fri, 23 Feb 2018 17:25:38 +0800 Subject: [PATCH] common: missing error checking in method KVDB::Has() and KVDB::Get() Except NotFound error, there may be other errors when accessing leveldb Get(), such as IOError. --- modules/common/kv_db/kv_db.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/common/kv_db/kv_db.cc b/modules/common/kv_db/kv_db.cc index b086520995..9d21c8ea50 100644 --- a/modules/common/kv_db/kv_db.cc +++ b/modules/common/kv_db/kv_db.cc @@ -86,7 +86,8 @@ bool KVDB::Has(const std::string &key) { std::string value; const auto status = GetDB()->Get(options, key, &value); - return !status.IsNotFound(); + CHECK(status.ok() || status.IsNotFound()) << status.ToString(); + return status.ok(); } std::string KVDB::Get(const std::string &key, @@ -95,6 +96,7 @@ std::string KVDB::Get(const std::string &key, std::string value; const auto status = GetDB()->Get(options, key, &value); + CHECK(status.ok() || status.IsNotFound()) << status.ToString(); return status.ok() ? value : default_value; } -- GitLab