stephencelis / SQLite.swift

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

FailableIterator next() crash #1028

Closed enamor closed 2 years ago

enamor commented 3 years ago

extension FailableIterator { public func next() -> Element? { return try! failableNext() } }

Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: disk I/O error (code: 10)

juanjoseluisgarcia commented 3 years ago

This occurs when more than one thread is trying to access the DB. This library is not thread-friendly. My suggestion is that you create one global connection (in the AppDelegate for example) and use that connection all over your app.

avnerbarr commented 3 years ago

issue also occurs if the db is open in 2 processes

nathanfallet commented 2 years ago

Merged a fix to replace try! by try?.

vitock commented 1 year ago

Merged a fix to replace try! by try?.

I saw you reverted that change ?

nathanfallet commented 1 year ago

Merged a fix to replace try! by try?.

I saw you reverted that change ?

Yes, because as explained in #1075, you should use failableNext() and handle the error by yourself using a do/catch block. We cannot provide a default behavior (e.g. return nil) when an error occurs, it's up to you to choose what you want to do.