Skip to content

Commit 9fffc5d

Browse files
authored
Fix erroneous move (#3769)
Here, the error actually has to be copied because it is passed to more than one listener. Currently, this doesn't make a difference because `util::Status` has no move constructor. Also, make the relevant method take the status by const reference.
1 parent 58cae6c commit 9fffc5d

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Firestore/core/src/firebase/firestore/core/event_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class EventManager : public SyncEngineCallback {
6767
// Implements `SyncEngineCallback`.
6868
void HandleOnlineStateChange(model::OnlineState online_state) override;
6969
void OnViewSnapshots(std::vector<core::ViewSnapshot>&& snapshots) override;
70-
void OnError(const core::Query& query, util::Status error) override;
70+
void OnError(const core::Query& query, const util::Status& error) override;
7171

7272
private:
7373
/**

Firestore/core/src/firebase/firestore/core/event_manager.mm

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,21 @@
9595
}
9696
}
9797

98-
void EventManager::OnError(const core::Query& query, util::Status error) {
98+
void EventManager::OnError(const core::Query& query,
99+
const util::Status& error) {
99100
auto found_iter = queries_.find(query);
100-
if (found_iter != queries_.end()) {
101-
QueryListenersInfo& query_info = found_iter->second;
102-
for (const auto& listener : query_info.listeners) {
103-
listener->OnError(std::move(error));
104-
}
101+
if (found_iter == queries_.end()) {
102+
return;
103+
}
105104

106-
// Remove all listeners. NOTE: We don't need to call [FSTSyncEngine
107-
// stopListening] after an error.
108-
queries_.erase(found_iter);
105+
QueryListenersInfo& query_info = found_iter->second;
106+
for (const auto& listener : query_info.listeners) {
107+
listener->OnError(error);
109108
}
109+
110+
// Remove all listeners. NOTE: We don't need to call [FSTSyncEngine
111+
// stopListening] after an error.
112+
queries_.erase(found_iter);
110113
}
111114

112115
} // namespace core

Firestore/core/src/firebase/firestore/core/sync_engine_callback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SyncEngineCallback {
3939
/** Handles new view snapshots. */
4040
virtual void OnViewSnapshots(std::vector<core::ViewSnapshot>&& snapshots) = 0;
4141
/** Handles the failure of a query. */
42-
virtual void OnError(const core::Query& query, util::Status error) = 0;
42+
virtual void OnError(const core::Query& query, const util::Status& error) = 0;
4343
};
4444

4545
} // namespace core

0 commit comments

Comments
 (0)