Skip to content

Commit de60ad2

Browse files
authored
[Collections] Should be able to delete a non-existent local collection (#3401)
Steps to reproduce: 1. Add a local collection 2. Delete or rename the local collection file 3. Try deleting the local collection Result: Error about local file not found Expected: Non-existent local collection deleted The `remove` collection subcommand calls `getCollection` API to fetch collection's name for displaying success message later. `getCollection` tries to fetch collection from storage, and if it's not found there, it fetches from the source directly. The error is caused by the source validation logic, which mistakenly is the first thing `getCollection` does but should really only be done when we need to fetch from the source.
1 parent 157cdb0 commit de60ad2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sources/PackageCollections/PackageCollections.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ public struct PackageCollections: PackageCollectionsProtocol {
262262
return callback(.failure(PackageCollectionError.unsupportedPlatform))
263263
}
264264

265-
if let errors = source.validate()?.errors() {
266-
return callback(.failure(MultipleErrors(errors)))
267-
}
268-
269265
self.storage.collections.get(identifier: .init(from: source)) { result in
270266
switch result {
271267
case .failure:
268+
// The collection is not in storage. Validate the source before fetching it.
269+
if let errors = source.validate()?.errors() {
270+
return callback(.failure(MultipleErrors(errors)))
271+
}
272272
guard let provider = self.collectionProviders[source.type] else {
273273
return callback(.failure(UnknownProvider(source.type)))
274274
}

0 commit comments

Comments
 (0)