Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Brave Ads logs should not show "Failed to initialize...resource" if component updater resource does not exist #18351

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/brave_ads/core/internal/ads_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace brave_ads {
namespace {

void FailedToInitialize(InitializeCallback callback) {
BLOG(1, "Failed to initialize ads");
BLOG(0, "Failed to initialize ads");

std::move(callback).Run(/*success*/ false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ void AntiTargetingResource::Load() {
void AntiTargetingResource::OnLoadAndParseResource(
ResourceParsingErrorOr<AntiTargetingInfo> result) {
if (!result.has_value()) {
BLOG(1, result.error());
BLOG(1,
"Failed to initialize " << kResourceId << " anti-targeting resource");
BLOG(0, "Failed to initialize "
<< kResourceId << " anti-targeting resource (" << result.error()
<< ")");
is_initialized_ = false;
return;
}

if (result.value().version == 0) {
BLOG(7, kResourceId << " anti-targeting resource does not exist");
is_initialized_ = false;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ void ConversionsResource::Load() {
void ConversionsResource::OnLoadAndParseResource(
ResourceParsingErrorOr<ConversionsInfo> result) {
if (!result.has_value()) {
BLOG(1, result.error());
BLOG(1, "Failed to initialize " << kResourceId << " conversions resource");
BLOG(0, "Failed to initialize " << kResourceId << " conversions resource ("
<< result.error() << ")");
is_initialized_ = false;
return;
}

if (result.value().version == 0) {
BLOG(7, kResourceId << " conversions resource does not exist");
is_initialized_ = false;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ void PurchaseIntentResource::Load() {
void PurchaseIntentResource::OnLoadAndParseResource(
ResourceParsingErrorOr<PurchaseIntentInfo> result) {
if (!result.has_value()) {
BLOG(1, result.error());
BLOG(1,
"Failed to initialize " << kResourceId << " purchase intent resource");
BLOG(0, "Failed to initialize " << kResourceId
<< " purchase intent resource ("
<< result.error() << ")");
is_initialized_ = false;
return;
}

if (result.value().version == 0) {
BLOG(7, kResourceId << " purchase intent resource does not exist");
is_initialized_ = false;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ void TextClassificationResource::Load() {
void TextClassificationResource::OnLoadAndParseResource(
ResourceParsingErrorOr<ml::pipeline::TextProcessing> result) {
if (!result.has_value()) {
BLOG(1, result.error());
BLOG(1, "Failed to initialize " << kResourceId
<< " text classification resource");
BLOG(0, "Failed to initialize " << kResourceId
<< " text classification resource ("
<< result.error() << ")");
return;
}

if (!result.value().IsInitialized()) {
BLOG(7, kResourceId << " text classification resource does not exist");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ void TextEmbeddingResource::Load() {
void TextEmbeddingResource::OnLoadAndParseResource(
ResourceParsingErrorOr<ml::pipeline::EmbeddingProcessing> result) {
if (!result.has_value()) {
BLOG(1, result.error());
BLOG(1,
"Failed to initialize " << kResourceId << " text embedding resource");
BLOG(0, "Failed to initialize "
<< kResourceId << " text embedding resource (" << result.error()
<< ")");
return;
}

if (!result.value().IsInitialized()) {
BLOG(7, kResourceId << " text embedding resource does not exist");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ template <typename T>
base::expected<T, std::string> ReadFileAndParseResourceOnBackgroundThread(
base::File file) {
if (!file.IsValid()) {
return base::unexpected("File is not valid");
return base::ok(T{});
}

absl::optional<base::Value> root;
Expand All @@ -41,12 +41,12 @@ base::expected<T, std::string> ReadFileAndParseResourceOnBackgroundThread(
std::string content;
const base::ScopedFILE scoped_file(base::FileToFILE(std::move(file), "rb"));
if (!base::ReadStreamToString(scoped_file.get(), &content)) {
return base::unexpected("Couldn't read file");
return base::unexpected("Failed to read file");
}

root = base::JSONReader::Read(content);
if (!root || !root->is_dict()) {
return base::unexpected("Failed to parse JSON");
return base::unexpected("Invalid JSON");
}
}

Expand Down