Handle json parse failures

Summary: Loading the deviceId is not critical, so if it ever fails, we can live with that by swallowing the exception and using the default (possibly 'unknown' deviceId).

Reviewed By: danielbuechele

Differential Revision: D9682886

fbshipit-source-id: e5d60dd262fce683dd444167edd1475e0c029759
This commit is contained in:
John Knox
2018-09-06 09:46:22 -07:00
committed by Facebook Github Bot
parent 9cfb461a9a
commit d16fd8cfae

View File

@@ -64,9 +64,13 @@ std::string ConnectionContextStore::getDeviceId() {
desktop app. desktop app.
For backwards compatibility, when this isn't present, fall back to the For backwards compatibility, when this isn't present, fall back to the
unreliable source. */ unreliable source. */
std::string config = loadStringFromFile(absoluteFilePath(CONNECTION_CONFIG_FILE)); try {
auto maybeDeviceId = folly::parseJson(config)["deviceId"]; std::string config = loadStringFromFile(absoluteFilePath(CONNECTION_CONFIG_FILE));
return maybeDeviceId.isString() ? maybeDeviceId.getString() : deviceData_.deviceId; auto maybeDeviceId = folly::parseJson(config)["deviceId"];
return maybeDeviceId.isString() ? maybeDeviceId.getString() : deviceData_.deviceId;
} catch (std::exception& e) {
return deviceData_.deviceId;
}
} }
void ConnectionContextStore::storeConnectionConfig(folly::dynamic& config) { void ConnectionContextStore::storeConnectionConfig(folly::dynamic& config) {