17
17
#include " Firestore/core/src/core/order_by.h"
18
18
19
19
#include < ostream>
20
+ #include < sstream>
20
21
21
22
#include " Firestore/core/src/model/document.h"
22
23
#include " Firestore/core/src/model/value_util.h"
@@ -31,6 +32,38 @@ using model::Document;
31
32
using model::FieldPath;
32
33
using util::ComparisonResult;
33
34
35
+ namespace {
36
+
37
+ void AssertBothOptionalsHaveValues (
38
+ const model::FieldPath& field_path,
39
+ const absl::optional<google_firestore_v1_Value>& value1,
40
+ const absl::optional<google_firestore_v1_Value>& value2,
41
+ const Document& lhs,
42
+ const Document& rhs) {
43
+ if (value1.has_value () && value2.has_value ()) {
44
+ return ;
45
+ }
46
+
47
+ std::ostringstream ss;
48
+ ss << " Trying to compare documents on fields that don't exist;"
49
+ << " field_path=" << field_path.CanonicalString ()
50
+ << " , lhs=" << lhs->key ().ToString () << " , rhs=" << rhs->key ().ToString ()
51
+ << " , value1.has_value()=" << (value1.has_value () ? " true" : " false" )
52
+ << " , value2.has_value()=" << (value2.has_value () ? " true" : " false" );
53
+
54
+ if (value1.has_value ()) {
55
+ ss << " , value1=" << value1->ToString ();
56
+ }
57
+ if (value2.has_value ()) {
58
+ ss << " , value2=" << value2->ToString ();
59
+ }
60
+
61
+ std::string message = ss.str ();
62
+ HARD_FAIL (message.c_str ());
63
+ }
64
+
65
+ } // namespace
66
+
34
67
ComparisonResult OrderBy::Compare (const Document& lhs,
35
68
const Document& rhs) const {
36
69
ComparisonResult result;
@@ -39,8 +72,7 @@ ComparisonResult OrderBy::Compare(const Document& lhs,
39
72
} else {
40
73
absl::optional<google_firestore_v1_Value> value1 = lhs->field (field_);
41
74
absl::optional<google_firestore_v1_Value> value2 = rhs->field (field_);
42
- HARD_ASSERT (value1.has_value () && value2.has_value (),
43
- " Trying to compare documents on fields that don't exist." );
75
+ AssertBothOptionalsHaveValues (field_, value1, value2, lhs, rhs);
44
76
result = model::Compare (*value1, *value2);
45
77
}
46
78
0 commit comments