Commit a1836464 authored by Nigel Tao's avatar Nigel Tao Committed by Commit Bot

Check JSON value instead of error_code

Checking (result.error_code != JSON_NO_ERROR) is equivalent to checking
result.value (which has a base::Optional type, convertible to bool).

The error_code enum is really a private implementation detail. Callers
don't care about it (other than it being an error or no error). Removing
references (outside of //base/json) to that enum will let us more easily
modify the //base/json implementation.

Bug: 1070409
Change-Id: Ifffa60fa05d5dd2f52fabe0a2d6794db187e0f1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147400Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Reviewed-by: default avatarVincent Boisselle <vincb@google.com>
Commit-Queue: Nigel Tao <nigeltao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759057}
parent 08016216
...@@ -428,18 +428,12 @@ ServerCacheReplayer::Status PopulateCacheFromJSONFile( ...@@ -428,18 +428,12 @@ ServerCacheReplayer::Status PopulateCacheFromJSONFile(
JSONReader::ValueWithError value_with_error = JSONReader::ValueWithError value_with_error =
JSONReader().ReadAndReturnValueWithError( JSONReader().ReadAndReturnValueWithError(
decompressed_json_text, JSONParserOptions::JSON_PARSE_RFC); decompressed_json_text, JSONParserOptions::JSON_PARSE_RFC);
if (value_with_error.error_code != if (!value_with_error.value) {
JSONReader::JsonParseError::JSON_NO_ERROR) {
return ServerCacheReplayer::Status{ return ServerCacheReplayer::Status{
ServerCacheReplayer::StatusCode::kBadRead, ServerCacheReplayer::StatusCode::kBadRead,
base::StrCat({"Could not load cache from json file ", base::StrCat({"Could not load cache from json file ",
"because: ", value_with_error.error_message})}; "because: ", value_with_error.error_message})};
} }
if (value_with_error.value == base::nullopt) {
return ServerCacheReplayer::Status{
ServerCacheReplayer::StatusCode::kBadRead,
"JSON Reader could not give any node object from json file"};
}
root_node = std::move(value_with_error.value.value()); root_node = std::move(value_with_error.value.value());
} }
......
...@@ -111,17 +111,12 @@ std::vector<CapturedSiteParams> GetCapturedSites( ...@@ -111,17 +111,12 @@ std::vector<CapturedSiteParams> GetCapturedSites(
JSONReader::ValueWithError value_with_error = JSONReader::ValueWithError value_with_error =
JSONReader().ReadAndReturnValueWithError( JSONReader().ReadAndReturnValueWithError(
json_text, JSONParserOptions::JSON_PARSE_RFC); json_text, JSONParserOptions::JSON_PARSE_RFC);
if (value_with_error.error_code != if (!value_with_error.value) {
JSONReader::JsonParseError::JSON_NO_ERROR) {
LOG(WARNING) << "Could not load test config from json file: " LOG(WARNING) << "Could not load test config from json file: "
<< "`testcases.json` because: " << "`testcases.json` because: "
<< value_with_error.error_message; << value_with_error.error_message;
return sites; return sites;
} }
if (!value_with_error.value) {
LOG(WARNING) << "JSON Reader could not any object from `testcases.json`";
return sites;
}
root_node = std::move(value_with_error.value.value()); root_node = std::move(value_with_error.value.value());
} }
base::Value* list_node = root_node.FindListKey("tests"); base::Value* list_node = root_node.FindListKey("tests");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment