             // Reset the schema cache before running user code in snapshot isolation
             db.schemaCache = SimpleDatabaseSchemaCache()
             block(db)
-            
-        }
+        }
+        
         _ = semaphore.wait(timeout: .distantFuture)
-        if let readError = readError {
+        
+        if let error = snapshotIsolationError {
             // TODO: write a test for this
-            throw readError
+            throw error
         }
     }
     

                // Fetch and release the future
                futureResult = Result { try block(db) }
                futureSemaphore.signal()
                
            }
        } catch {
            return Future { throw error }

        // isolation has been established:
        let semaphore = DispatchSemaphore(value: 0)
        
        var snapshotIsolationError: Error? = nil
        let (reader, releaseReader) = try readerPool.get()
        reader.async { db in
            defer {
                _ = try? db.commit() // Ignore commit error
                releaseReader()
            }
            do {
                try db.beginSnapshotIsolation()
            } catch {
                snapshotIsolationError = error
                semaphore.signal() // Release the writer queue and rethrow error
                return
            }
