Skip to content

[5.5][Collections] Throw error instead of preconditionFailure after storage closed #3513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct GitHubPackageMetadataProvider: PackageMetadataProvider {

public var name: String = "GitHub"

var configuration: Configuration
let configuration: Configuration

private let httpClient: HTTPClient
private let diagnosticsEngine: DiagnosticsEngine?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
}

internal func populateTargetTrie(callback: @escaping (Result<Void, Error>) -> Void = { _ in }) {
DispatchQueue.sharedConcurrent.async(group: nil, qos: .background, flags: .assignCurrentContext, execute: {
DispatchQueue.sharedConcurrent.async(group: nil, qos: .background, flags: .assignCurrentContext) {
self.targetTrieReady.memoize {
do {
// since running on low priority thread make sure the database has not already gone away
Expand All @@ -771,6 +771,7 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
default:
break
}

// Use FTS to build the trie
let query = "SELECT collection_id_blob_base64, package_repository_url, name FROM \(Self.targetsFTSName);"
try self.executeStatement(query) { statement in
Expand Down Expand Up @@ -802,7 +803,7 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
return false
}
}
})
}
}

// for testing
Expand Down Expand Up @@ -842,7 +843,7 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
let db: SQLite
switch (self.location, self.state) {
case (_, .disconnecting), (_, .disconnected):
preconditionFailure("DB id disconnecting or disconnected")
throw StringError("DB is disconnecting or disconnected")
case (.path(let path), .connected(let database)):
if self.fileSystem.exists(path) {
db = database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ class GitHubPackageMetadataProviderTests: XCTestCase {
httpClient.configuration.retryStrategy = .none
var configuration = GitHubPackageMetadataProvider.Configuration()
configuration.cacheDir = tmpPath
var provider = GitHubPackageMetadataProvider(configuration: configuration, httpClient: httpClient)
provider.configuration.authTokens = { authTokens }
configuration.authTokens = { authTokens }
let provider = GitHubPackageMetadataProvider(configuration: configuration, httpClient: httpClient)
defer { XCTAssertNoThrow(try provider.close()) }

let reference = PackageReference(repository: RepositorySpecifier(url: repoURL))
Expand Down