Skip to content

Commit 23b19ee

Browse files
var-consta-maurice
authored andcommitted
Temporarily avoid usage of util::ThrowInvalidArgument in google3.
The implementation of `util::ThrowInvalidArgument` calls `util::StringFormat`, which can cause linkage errors on iOS because it has `absl::string_view` in its signature (which resolves to different types between the Abseil version in google3 and what's available publicly). As a temporary workaround, call `util::Throw` directly. PiperOrigin-RevId: 296075191
1 parent e9414dd commit 23b19ee

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

firestore/src/ios/hard_assert_ios.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "firestore/src/ios/hard_assert_ios.h"
2+
3+
namespace firebase {
4+
namespace firestore {
5+
namespace util {
6+
7+
ABSL_ATTRIBUTE_NORETURN void ThrowInvalidArgumentIos(
8+
const std::string& message) {
9+
Throw(ExceptionType::InvalidArgument, nullptr, nullptr, 0, message);
10+
}
11+
12+
} // namespace util
13+
} // namespace firestore
14+
} // namespace firebase

firestore/src/ios/hard_assert_ios.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include "Firestore/core/src/firebase/firestore/util/exception.h"
2525

2626
// TODO(b/147444199): delete this file and use the one that comes from the
27-
// GitHub repo. This file provides simplified versions of `HARD_ASSERT` and
28-
// `HARD_FAIL` that don't support string formatting.
27+
// GitHub repo. This file provides simplified versions of `HARD_ASSERT`,
28+
// `HARD_FAIL`, and `ThrowInvalidArgument` that don't support string formatting.
2929

3030
#if defined(_MSC_VER)
3131
#define FIRESTORE_FUNCTION_NAME __FUNCSIG__
@@ -116,6 +116,13 @@ ABSL_ATTRIBUTE_NORETURN void FailAssertion(const char* file, const char* func,
116116
const char* condition);
117117

118118
} // namespace internal
119+
120+
// This is a workaround for the fact that `util::ThrowInvalidArgument` calls
121+
// `StringFormat` in its implementation, which leads to linkage problems due to
122+
// the use of `absl::string_view` in its signature.
123+
ABSL_ATTRIBUTE_NORETURN void ThrowInvalidArgumentIos(
124+
const std::string& message);
125+
119126
} // namespace util
120127
} // namespace firestore
121128
} // namespace firebase

firestore/src/ios/query_ios.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace firestore {
2525

2626
using model::DocumentKey;
2727
using model::ResourcePath;
28-
using util::ThrowInvalidArgument;
28+
using util::ThrowInvalidArgumentIos;
2929

3030
QueryInternal::QueryInternal(api::Query&& query)
3131
: query_{std::move(query)},
@@ -124,7 +124,7 @@ bool operator==(const QueryInternal& lhs, const QueryInternal& rhs) {
124124
core::Bound QueryInternal::ToBound(
125125
BoundPosition bound_pos, const DocumentSnapshot& public_snapshot) const {
126126
if (!public_snapshot.exists()) {
127-
ThrowInvalidArgument(
127+
ThrowInvalidArgumentIos(
128128
"Invalid query. You are trying to start or end a query using a "
129129
"document that doesn't exist.");
130130
}
@@ -163,7 +163,7 @@ core::Bound QueryInternal::ToBound(
163163
"query using a document for which the field '") +
164164
field_path.CanonicalString() +
165165
"' (used as the order by) does not exist.";
166-
ThrowInvalidArgument(message.c_str());
166+
ThrowInvalidArgumentIos(message.c_str());
167167
}
168168

169169
if (value->type() == model::FieldValue::Type::ServerTimestamp) {
@@ -181,7 +181,7 @@ core::Bound QueryInternal::ToBound(
181181
field_path.CanonicalString() +
182182
"' is an uncommitted server timestamp. (Since the value of this"
183183
"field is unknown, you cannot start/end a query with it.)";
184-
ThrowInvalidArgument(message.c_str());
184+
ThrowInvalidArgumentIos(message.c_str());
185185
}
186186

187187
components.push_back(std::move(value).value());
@@ -199,7 +199,7 @@ core::Bound QueryInternal::ToBound(
199199
internal_query.explicit_order_bys();
200200

201201
if (field_values.size() > explicit_order_bys.size()) {
202-
ThrowInvalidArgument(
202+
ThrowInvalidArgumentIos(
203203
"Invalid query. You are trying to start or end a query using more "
204204
"values than were specified in the order by.");
205205
}
@@ -223,7 +223,7 @@ core::Bound QueryInternal::ToBound(
223223
model::FieldValue QueryInternal::ConvertDocumentId(
224224
const model::FieldValue& from, const core::Query& internal_query) const {
225225
if (from.type() != model::FieldValue::Type::String) {
226-
ThrowInvalidArgument(
226+
ThrowInvalidArgumentIos(
227227
"Invalid query. Expected a string for the document ID.");
228228
}
229229
const std::string& document_id = from.string_value();
@@ -240,7 +240,7 @@ model::FieldValue QueryInternal::ConvertDocumentId(
240240
"by document "
241241
"ID, you must pass a plain document ID, but '") +
242242
document_id + "' contains a slash.";
243-
ThrowInvalidArgument(message.c_str());
243+
ThrowInvalidArgumentIos(message.c_str());
244244
}
245245

246246
ResourcePath path =
@@ -259,7 +259,7 @@ model::FieldValue QueryInternal::ConvertDocumentId(
259259
"document path, but '") +
260260
path.CanonicalString() +
261261
"' is not because it contains an odd number of segments.";
262-
ThrowInvalidArgument(message.c_str());
262+
ThrowInvalidArgumentIos(message.c_str());
263263
}
264264

265265
const model::DatabaseId& database_id = firestore_internal()->database_id();

firestore/src/ios/user_data_converter_ios.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ using model::NumericIncrementTransform;
3131
using model::ServerTimestampTransform;
3232
using model::TransformOperation;
3333
using nanopb::ByteString;
34-
using util::ThrowInvalidArgument;
34+
using util::ThrowInvalidArgumentIos;
3535

3636
using Type = FieldValue::Type;
3737

@@ -58,7 +58,7 @@ void ParseDelete(ParseContext&& context) {
5858
"FieldValue::Delete() can only appear at the top level of your "
5959
"update data") +
6060
context.FieldDescription();
61-
ThrowInvalidArgument(message.c_str());
61+
ThrowInvalidArgumentIos(message.c_str());
6262
}
6363

6464
// We shouldn't encounter delete sentinels for queries or non-merge `Set`
@@ -73,7 +73,7 @@ void ParseDelete(ParseContext&& context) {
7373
"FieldValue::Delete() can only be used with Update() and Set() with "
7474
"merge == true") +
7575
context.FieldDescription();
76-
ThrowInvalidArgument(message.c_str());
76+
ThrowInvalidArgumentIos(message.c_str());
7777
}
7878

7979
void ParseServerTimestamp(ParseContext&& context) {
@@ -141,7 +141,7 @@ FieldMask CreateFieldMask(const ParseAccumulator& accumulator,
141141
auto message =
142142
std::string("Field '") + path.CanonicalString() +
143143
"' is specified in your field mask but missing from your input data.";
144-
ThrowInvalidArgument(message.c_str());
144+
ThrowInvalidArgumentIos(message.c_str());
145145
}
146146

147147
validated.insert(path);
@@ -273,7 +273,7 @@ model::FieldValue::Array UserDataConverter::ParseArray(
273273
// disable this validation.
274274
if (context.array_element() &&
275275
context.data_source() != core::UserDataSource::ArrayArgument) {
276-
ThrowInvalidArgument("Nested arrays are not supported");
276+
ThrowInvalidArgumentIos("Nested arrays are not supported");
277277
}
278278

279279
model::FieldValue::Array result;
@@ -325,7 +325,7 @@ void UserDataConverter::ParseSentinel(const FieldValue& value,
325325
auto message = Describe(value.type()) +
326326
" can only be used with Update() and Set()" +
327327
context.FieldDescription();
328-
ThrowInvalidArgument(message.c_str());
328+
ThrowInvalidArgumentIos(message.c_str());
329329
}
330330

331331
if (!context.path()) {
@@ -334,7 +334,7 @@ void UserDataConverter::ParseSentinel(const FieldValue& value,
334334
// Describe(value.type()));
335335
auto message =
336336
Describe(value.type()) + " is not currently supported inside arrays";
337-
ThrowInvalidArgument(message.c_str());
337+
ThrowInvalidArgumentIos(message.c_str());
338338
}
339339

340340
switch (value.type()) {
@@ -415,7 +415,7 @@ model::FieldValue UserDataConverter::ParseScalar(const FieldValue& value,
415415
auto message = std::string("DocumentReference is for database ") +
416416
actual_db + " but should be for database " +
417417
expected_db + context.FieldDescription();
418-
ThrowInvalidArgument(message.c_str());
418+
ThrowInvalidArgumentIos(message.c_str());
419419
}
420420

421421
const model::DocumentKey& key = GetInternal(&reference)->key();

0 commit comments

Comments
 (0)