Skip to content

Commit ee39677

Browse files
Adding CHECKs to all JSON string serialisation
For the types used by brave ads and ledger which we have to serialise, it is possible to have failure, although we don't expect to see it. This change adds a check to the result, so we may catch any cases in which it might be taking place.
1 parent b9bada1 commit ee39677

File tree

11 files changed

+20
-11
lines changed

11 files changed

+20
-11
lines changed

vendor/bat-native-ads/src/bat/ads/ad_content_info.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "bat/ads/ad_content_info.h"
77

8+
#include "base/check.h"
89
#include "base/json/json_reader.h"
910
#include "base/json/json_writer.h"
1011
#include "bat/ads/internal/base/logging_util.h"
@@ -137,7 +138,7 @@ bool AdContentInfo::FromValue(const base::Value::Dict& root) {
137138

138139
std::string AdContentInfo::ToJson() const {
139140
std::string json;
140-
base::JSONWriter::Write(ToValue(), &json);
141+
CHECK(base::JSONWriter::Write(ToValue(), &json));
141142
return json;
142143
}
143144

vendor/bat-native-ads/src/bat/ads/history_info.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "bat/ads/history_info.h"
77

8+
#include "base/check.h"
89
#include "base/json/json_reader.h"
910
#include "base/json/json_writer.h"
1011
#include "bat/ads/history_item_info.h"
@@ -48,7 +49,7 @@ bool HistoryInfo::FromValue(const base::Value::Dict& root) {
4849

4950
std::string HistoryInfo::ToJson() const {
5051
std::string json;
51-
base::JSONWriter::Write(ToValue(), &json);
52+
CHECK(base::JSONWriter::Write(ToValue(), &json));
5253
return json;
5354
}
5455

vendor/bat-native-ads/src/bat/ads/inline_content_ad_info.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "bat/ads/inline_content_ad_info.h"
77

8+
#include "base/check.h"
89
#include "base/json/json_reader.h"
910
#include "base/json/json_writer.h"
1011
#include "bat/ads/confirmation_type.h"
@@ -121,7 +122,7 @@ bool InlineContentAdInfo::FromValue(const base::Value::Dict& root) {
121122

122123
std::string InlineContentAdInfo::ToJson() const {
123124
std::string json;
124-
base::JSONWriter::Write(ToValue(), &json);
125+
CHECK(base::JSONWriter::Write(ToValue(), &json));
125126
return json;
126127
}
127128

vendor/bat-native-ads/src/bat/ads/internal/deprecated/client/client_info.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ bool ClientInfo::FromValue(const base::Value::Dict& root) {
212212

213213
std::string ClientInfo::ToJson() {
214214
std::string json;
215-
base::JSONWriter::Write(ToValue(), &json);
215+
CHECK(base::JSONWriter::Write(ToValue(), &json));
216216
return json;
217217
}
218218

vendor/bat-native-ads/src/bat/ads/internal/deprecated/client/preferences/ad_preferences_info.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <utility>
99

10+
#include "base/check.h"
1011
#include "base/json/json_reader.h"
1112
#include "base/json/json_writer.h"
1213

@@ -129,7 +130,7 @@ bool AdPreferencesInfo::FromValue(const base::Value::Dict& root) {
129130

130131
std::string AdPreferencesInfo::ToJson() const {
131132
std::string json;
132-
base::JSONWriter::Write(ToValue(), &json);
133+
CHECK(base::JSONWriter::Write(ToValue(), &json));
133134
return json;
134135
}
135136

vendor/bat-native-ads/src/bat/ads/new_tab_page_ad_info.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <tuple>
99

10+
#include "base/check.h"
1011
#include "base/json/json_reader.h"
1112
#include "base/json/json_writer.h"
1213

@@ -156,7 +157,7 @@ bool NewTabPageAdInfo::FromValue(const base::Value::Dict& root) {
156157

157158
std::string NewTabPageAdInfo::ToJson() const {
158159
std::string json;
159-
base::JSONWriter::Write(ToValue(), &json);
160+
CHECK(base::JSONWriter::Write(ToValue(), &json));
160161
return json;
161162
}
162163

vendor/bat-native-ads/src/bat/ads/notification_ad_info.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool NotificationAdInfo::FromValue(const base::Value::Dict& root) {
9494

9595
std::string NotificationAdInfo::ToJson() const {
9696
std::string json;
97-
base::JSONWriter::Write(ToValue(), &json);
97+
CHECK(base::JSONWriter::Write(ToValue(), &json));
9898
return json;
9999
}
100100

vendor/bat-native-ledger/src/bat/ledger/internal/legacy/client_properties.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <utility>
99

10+
#include "base/check.h"
1011
#include "base/json/json_reader.h"
1112
#include "base/json/json_writer.h"
1213
#include "base/json/values_util.h"
@@ -173,7 +174,7 @@ bool ClientProperties::FromValue(const base::Value::Dict& dict) {
173174

174175
std::string ClientProperties::ToJson() const {
175176
std::string json;
176-
base::JSONWriter::Write(ToValue(), &json);
177+
CHECK(base::JSONWriter::Write(ToValue(), &json));
177178
return json;
178179
}
179180

vendor/bat-native-ledger/src/bat/ledger/internal/legacy/publisher_settings_properties.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <utility>
99

10+
#include "base/check.h"
1011
#include "base/json/json_reader.h"
1112
#include "base/json/json_writer.h"
1213
#include "base/json/values_util.h"
@@ -188,7 +189,7 @@ bool PublisherSettingsProperties::FromValue(const base::Value::Dict& dict) {
188189

189190
std::string PublisherSettingsProperties::ToJson() const {
190191
std::string json;
191-
base::JSONWriter::Write(ToValue(), &json);
192+
CHECK(base::JSONWriter::Write(ToValue(), &json));
192193
return json;
193194
}
194195

vendor/bat-native-ledger/src/bat/ledger/internal/legacy/report_balance_properties.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "bat/ledger/internal/legacy/report_balance_properties.h"
77

8+
#include "base/check.h"
89
#include "base/json/json_reader.h"
910
#include "base/json/json_writer.h"
1011
#include "base/logging.h"
@@ -134,7 +135,7 @@ bool ReportBalanceProperties::FromValue(const base::Value::Dict& dict) {
134135

135136
std::string ReportBalanceProperties::ToJson() const {
136137
std::string json;
137-
base::JSONWriter::Write(ToValue(), &json);
138+
CHECK(base::JSONWriter::Write(ToValue(), &json));
138139
return json;
139140
}
140141

vendor/bat-native-ledger/src/bat/ledger/internal/legacy/wallet_info_properties.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "bat/ledger/internal/legacy/wallet_info_properties.h"
77

88
#include "base/base64.h"
9+
#include "base/check.h"
910
#include "base/json/json_reader.h"
1011
#include "base/json/json_writer.h"
1112
#include "base/logging.h"
@@ -94,7 +95,7 @@ bool WalletInfoProperties::FromValue(const base::Value::Dict& dict) {
9495

9596
std::string WalletInfoProperties::ToJson() const {
9697
std::string json;
97-
base::JSONWriter::Write(ToValue(), &json);
98+
CHECK(base::JSONWriter::Write(ToValue(), &json));
9899
return json;
99100
}
100101

0 commit comments

Comments
 (0)