Skip to content

Commit 2c7e617

Browse files
mjorasfacebook-github-bot
authored andcommitted
Broader exception catch for FilePersistenceLayer
Summary: folly::readFile can throw. Additionally, let's make sure we catch any sort of exception here and log it. Not being able to load the file is already not considered to be fatal. Reviewed By: vchynarov Differential Revision: D29366955 fbshipit-source-id: a450bf9880627f355fa9aaffb15bd99784d25a91
1 parent cb42176 commit 2c7e617

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

wangle/client/persistence/FilePersistenceLayer.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include <exception>
18+
1719
#include <folly/FileUtil.h>
1820
#include <folly/portability/Unistd.h>
1921
#include <folly/json.h>
@@ -70,18 +72,22 @@ folly::Optional<folly::dynamic> FilePersistenceLayer::load() noexcept {
7072
// not being able to read the backing storage means we just
7173
// start with an empty cache. Failing to deserialize, or write,
7274
// is a real error so we report errors there.
73-
if (!folly::readFile(file_.c_str(), serializedCache)) {
74-
return folly::none;
75-
}
76-
75+
std::string exceptionWhat;
7776
try {
77+
if (!folly::readFile(file_.c_str(), serializedCache)) {
78+
return folly::none;
79+
}
80+
7881
folly::json::serialization_opts opts;
7982
opts.allow_non_string_keys = true;
8083
return folly::parseJson(serializedCache, opts);
8184
} catch (const std::exception& err) {
82-
LOG(ERROR) << "Deserialization of cache file " << file_
83-
<< " failed with parse error: " << err.what();
85+
exceptionWhat = err.what();
86+
} catch (...) {
87+
exceptionWhat = "Non-standard excpetion";
8488
}
89+
LOG(ERROR) << "Deserialization of cache file " << file_
90+
<< " failed with error: " << exceptionWhat;
8591
return folly::none;
8692
}
8793

0 commit comments

Comments
 (0)