From 86eefea25897a8f64ad4a549d2178ace92662d98 Mon Sep 17 00:00:00 2001 From: Shannon Young Date: Sun, 21 Jul 2024 20:03:41 -0700 Subject: [PATCH 1/2] Fix: Do not force try `FailableIterator.next()` --- Sources/SQLite/Core/Statement.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SQLite/Core/Statement.swift b/Sources/SQLite/Core/Statement.swift index 6cb2e5d3..465a441c 100644 --- a/Sources/SQLite/Core/Statement.swift +++ b/Sources/SQLite/Core/Statement.swift @@ -214,8 +214,8 @@ public protocol FailableIterator: IteratorProtocol { extension FailableIterator { public func next() -> Element? { - // swiftlint:disable:next force_try - try! failableNext() + // Do not force try + try? failableNext() } } From b1d680640fa38a8676bc1ebb43a2d9df22efb0a9 Mon Sep 17 00:00:00 2001 From: Shannon Young Date: Sun, 21 Jul 2024 20:11:51 -0700 Subject: [PATCH 2/2] Fix: Use failableNext() in prepare so that if the try fails it will rethrow --- Sources/SQLite/Typed/Query.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/SQLite/Typed/Query.swift b/Sources/SQLite/Typed/Query.swift index 2a83665c..b5d11ac2 100644 --- a/Sources/SQLite/Typed/Query.swift +++ b/Sources/SQLite/Typed/Query.swift @@ -1009,10 +1009,9 @@ extension Connection { let statement = try prepare(expression.template, expression.bindings) let columnNames = try columnNamesForQuery(query) + let rows = try statement.failableNext().map { Row(columnNames, $0) } - return AnySequence { - AnyIterator { statement.next().map { Row(columnNames, $0) } } - } + return AnySequence { AnyIterator { rows } } } public func prepareRowIterator(_ query: QueryType) throws -> RowIterator {