diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift index c0597a6e98..8708109045 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift @@ -142,12 +142,16 @@ class AnalyticsEventSQLStorage: AnalyticsEventStorage { ORDER BY timestamp ASC LIMIT ? """ - let rows = try dbAdapter.executeQuery(queryStatement, [limit]) + let rows = try dbAdapter.executeQuery(queryStatement, [limit]).makeIterator() var result = [PinpointEvent]() - for element in rows { - if let event = PinpointEvent.convertToEvent(element) { - result.append(event) + do { + while let element = try rows.failableNext() { + if let event = PinpointEvent.convertToEvent(element) { + result.append(event) + } } + } catch { + Self.log.debug("Failed to iterate event rows from SQLite, error: \(error)") } return result }