Skip to content

Commit 16e0e9c

Browse files
authored
Improve package collection validation error message (#4166)
rdar://89172182
1 parent 4297451 commit 16e0e9c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Sources/PackageCollections/PackageCollections+Validation.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -80,7 +80,7 @@ extension PackageCollectionModel.V1 {
8080

8181
// TODO: validate package url?
8282
private func validate(package: Collection.Package, messages: inout [ValidationMessage]) {
83-
let packageID = PackageIdentity(url: package.url).description
83+
let packageID = "\(PackageIdentity(url: package.url).description) (\(package.url.absoluteString))"
8484

8585
guard !package.versions.isEmpty else {
8686
messages.append(.error("Package \(packageID) does not have any versions.", property: "package.versions"))
@@ -145,7 +145,7 @@ extension PackageCollectionModel.V1 {
145145

146146
version.manifests.forEach { toolsVersion, manifest in
147147
if toolsVersion != manifest.toolsVersion {
148-
messages.append(.error("Manifest tools version \(manifest.toolsVersion) does not match \(toolsVersion)", property: "version.manifest"))
148+
messages.append(.error("Package \(packageID) manifest tools version \(manifest.toolsVersion) does not match \(toolsVersion)", property: "version.manifest"))
149149
}
150150

151151
if manifest.products.isEmpty {
@@ -231,6 +231,15 @@ extension Array where Element == ValidationMessage {
231231
public enum ValidationError: Error, Equatable, CustomStringConvertible {
232232
case property(name: String, message: String)
233233
case other(message: String)
234+
235+
public var message: String {
236+
switch self {
237+
case .property(_, let message):
238+
return message
239+
case .other(let message):
240+
return message
241+
}
242+
}
234243

235244
public var description: String {
236245
switch self {

Sources/PackageCollections/Providers/JSONPackageCollectionProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -195,7 +195,7 @@ struct JSONPackageCollectionProvider: PackageCollectionProvider {
195195
private func makeCollection(from collection: JSONModel.Collection, source: Model.CollectionSource, signature: Model.SignatureData?) -> Result<Model.Collection, Error> {
196196
do {
197197
if let errors = self.validator.validate(collection: collection)?.errors() {
198-
throw JSONPackageCollectionProviderError.invalidCollection("\(errors)")
198+
throw JSONPackageCollectionProviderError.invalidCollection("\(errors.map { $0.message }.joined(separator: " "))")
199199
}
200200

201201
var serializationOkay = true

0 commit comments

Comments
 (0)