stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.57k stars 1.55k forks source link

How to catch interrupted error? #1117

Closed brookhong closed 2 years ago

brookhong commented 2 years ago

Querying in some table is time-consuming, I want to intentionally interrupt previous query with db.interrupt(), which works fine.

But got below error from previous query, how can I catch the error without crashing the application?

SQLite/Statement.swift:211: Fatal error: 'try!' expression unexpectedly raised an error: interrupted (code: 9)

Tried below code, but to no avail.

    do {
        let sequences = try db.prepare(repos.select(key))
        rows = Array(sequences.enumerated())
    } catch {
        print(error)
    }
SaladDays831 commented 2 years ago

Also happening to me when I call db.interrupt() Crashes in Statement.swift, on

extension FailableIterator {
    public func next() -> Element? {
        // swiftlint:disable:next force_try
        try! failableNext()
    }
}
nathanfallet commented 2 years ago

Closing as it is a duplicate of #1118. We're going to keep only one issue opened to track this problem.