Skip to content

Commit 33877b1

Browse files
committed
Improve some diagnostics messages
<rdar://problem/50456674>
1 parent a5d1833 commit 33877b1

File tree

11 files changed

+33
-40
lines changed

11 files changed

+33
-40
lines changed

Sources/PackageDescription4/Version+StringLiteralConvertible.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension Version: ExpressibleByStringLiteral {
1818
// the error and initialize with a dummy value. This is done to
1919
// report error to the invoking tool (like swift build) gracefully
2020
// rather than just crashing.
21-
errors.append("Invalid version string: \(value)")
21+
errors.append("Invalid semantic version string '\(value)'")
2222
self.init(0, 0, 0)
2323
}
2424
}

Sources/PackageGraph/DependencyResolver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public enum DependencyResolverError: Error, Equatable, CustomStringConvertible {
6060
public var description: String {
6161
switch self {
6262
case .cancelled:
63-
return "the dependency resolution was cancelled"
63+
return "the package resolution operation was cancelled"
6464
case .unsatisfiable:
65-
return "unable to resolve dependencies"
65+
return "the package dependency graph could not be resolved due to an unknown conflict"
6666
case .cycle(let package):
6767
return "the package \(package) depends on itself"
6868
case let .incompatibleConstraints(dependency, revisions):
@@ -79,7 +79,7 @@ public enum DependencyResolverError: Error, Equatable, CustomStringConvertible {
7979

8080
case let .missingVersions(constraints):
8181
let stream = BufferedOutputByteStream()
82-
stream <<< "the package dependency graph is unresolvable; unable find any available tag for the following requirements:\n"
82+
stream <<< "the package dependency graph could not be resolved; unable find any available tag for the following requirements:\n"
8383
for (i, constraint) in constraints.enumerated() {
8484
stream <<< " "
8585
stream <<< "\(constraint.identifier.path)" <<< " @ "

Sources/PackageGraph/PackageGraphLoader.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum PackageGraphError: Swift.Error {
5454
case cycleDetected((path: [Manifest], cycle: [Manifest]))
5555

5656
/// The product dependency not found.
57-
case productDependencyNotFound(name: String, package: String?)
57+
case productDependencyNotFound(name: String, target: String)
5858

5959
/// The product dependency was found but the package name did not match.
6060
case productDependencyIncorrectPackage(name: String, package: String)
@@ -74,8 +74,8 @@ extension PackageGraphError: CustomStringConvertible {
7474
(cycle.path + cycle.cycle).map({ $0.name }).joined(separator: " -> ") +
7575
" -> " + cycle.cycle[0].name
7676

77-
case .productDependencyNotFound(let name, _):
78-
return "product dependency '\(name)' not found"
77+
case .productDependencyNotFound(let name, let target):
78+
return "Product '\(name)' not found. It is required by target '\(target)'."
7979

8080
case .productDependencyIncorrectPackage(let name, let package):
8181
return "product dependency '\(name)' in package '\(package)' not found"
@@ -346,7 +346,7 @@ private func createResolvedPackages(
346346
// found errors when there are more important errors to
347347
// resolve (like authentication issues).
348348
if !diagnostics.hasErrors {
349-
let error = PackageGraphError.productDependencyNotFound(name: productRef.name, package: productRef.package)
349+
let error = PackageGraphError.productDependencyNotFound(name: productRef.name, target: targetBuilder.target.name)
350350
diagnostics.emit(error, location: diagnosticLocation())
351351
}
352352
continue

Sources/PackageLoading/Diagnostics.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ public enum PackageBuilderDiagnostics {
2121
name: "org.swift.diags.pkg-builder.nosources",
2222
defaultBehavior: .warning,
2323
description: {
24-
$0 <<< "target" <<< { "'\($0.target)'" }
25-
$0 <<< "in package" <<< { "'\($0.package)'" }
26-
$0 <<< "contains no valid source files"
24+
$0 <<< "Source files for target" <<< { "\($0.target)" }
25+
$0 <<< "should be located under" <<< { "\($0.targetPath)" }
2726
}
2827
)
2928

30-
/// The name of the package.
31-
public let package: String
29+
/// The path of the target.
30+
public let targetPath: String
3231

3332
/// The name of the target which has no sources.
3433
public let target: String

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public enum ModuleError: Swift.Error {
2424
/// Indicates two targets with the same name and their corresponding packages.
2525
case duplicateModule(String, [String])
2626

27-
/// One or more referenced targets could not be found.
28-
case modulesNotFound([String])
27+
/// The eferenced target could not be found.
28+
case moduleNotFound(String)
2929

3030
/// Invalid custom path.
3131
case invalidCustomPath(target: String, path: String)
@@ -67,9 +67,8 @@ extension ModuleError: CustomStringConvertible {
6767
case .duplicateModule(let name, let packages):
6868
let packages = packages.joined(separator: ", ")
6969
return "multiple targets named '\(name)' in: \(packages)"
70-
case .modulesNotFound(let targets):
71-
let targets = targets.joined(separator: ", ")
72-
return "could not find source files for target(s): \(targets); use the 'path' property in the Swift 4 manifest to set a custom target path"
70+
case .moduleNotFound(let target):
71+
return "Source files for target \(target) should be located under 'Sources/\(target)', or a custom sources path can be set with the 'path' property in Package.swift"
7372
case .invalidLayout(let type):
7473
return "package has unsupported layout; \(type)"
7574
case .invalidManifestConfig(let package, let message):
@@ -456,7 +455,7 @@ public final class PackageBuilder {
456455
if fileSystem.isDirectory(path) {
457456
return path
458457
}
459-
throw ModuleError.modulesNotFound([target.name])
458+
throw ModuleError.moduleNotFound(target.name)
460459
}
461460

462461
// Create potential targets.
@@ -474,8 +473,8 @@ public final class PackageBuilder {
474473
let allReferencedModules = manifest.allReferencedModules()
475474
let potentialModulesName = Set(potentialModules.map({ $0.name }))
476475
let missingModules = allReferencedModules.subtracting(potentialModulesName).intersection(allReferencedModules)
477-
guard missingModules.isEmpty else {
478-
throw ModuleError.modulesNotFound(missingModules.map({ $0 }))
476+
if let missingModule = missingModules.first {
477+
throw ModuleError.moduleNotFound(missingModule)
479478
}
480479

481480
let targetItems = manifest.targets.map({ ($0.name, $0 as TargetDescription) })
@@ -562,7 +561,7 @@ public final class PackageBuilder {
562561
targets[createdTarget.name] = createdTarget
563562
} else {
564563
emptyModules.insert(potentialModule.name)
565-
diagnostics.emit(data: PackageBuilderDiagnostics.NoSources(package: manifest.name, target: potentialModule.name))
564+
diagnostics.emit(data: PackageBuilderDiagnostics.NoSources(targetPath: potentialModule.path.pathString, target: potentialModule.name))
566565
}
567566
}
568567
return targets.values.map({ $0 })

Sources/PackageModel/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ extension Package.Error: CustomStringConvertible {
9494
public var description: String {
9595
switch self {
9696
case .noManifest(let baseURL, let version):
97-
var string = "\(baseURL) has no manifest"
97+
var string = "\(baseURL) has no Package.swift manifest"
9898
if let version = version {
9999
string += " for version \(version)"
100100
}

Sources/Workspace/Diagnostics.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,21 @@ public enum ResolverDiagnostics {
8282
type: Unsatisfiable.self,
8383
name: "org.swift.diags.resolver.unsatisfiable",
8484
description: {
85-
$0 <<< "dependency graph is unresolvable;"
85+
$0 <<< "the package dependency graph could not be resolved;"
8686
$0 <<< .substitution({
8787
let `self` = $0 as! Unsatisfiable
8888

8989
// If we don't have any additional data, return empty string.
9090
if self.dependencies.isEmpty && self.pins.isEmpty {
9191
return ""
9292
}
93-
var diag = "found these conflicting requirements:"
93+
var diag = "possibly because of these requirements:"
9494
let indent = " "
9595

9696
if !self.dependencies.isEmpty {
97-
diag += "\n\nDependencies: \n"
9897
diag += self.dependencies.map({ indent + Unsatisfiable.toString($0) }).joined(separator: "\n")
9998
}
10099

101-
if !self.pins.isEmpty {
102-
diag += "\n\nPins: \n"
103-
diag += self.pins.map({ indent + Unsatisfiable.toString($0) }).joined(separator: "\n")
104-
}
105100
return diag
106101
}, preference: .default)
107102
}

Tests/PackageGraphTests/PackageGraphTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class PackageGraphTests: XCTestCase {
497497
)
498498

499499
DiagnosticsEngineTester(diagnostics) { result in
500-
result.check(diagnostic: "target 'Bar' in package 'Bar' contains no valid source files", behavior: .warning)
500+
result.check(diagnostic: "Source files for target Bar should be located under /Bar/Sources/Bar", behavior: .warning)
501501
result.check(diagnostic: "target 'Bar' referenced in product 'Bar' could not be found", behavior: .error, location: "'Bar' /Bar")
502502
}
503503
}
@@ -521,7 +521,7 @@ class PackageGraphTests: XCTestCase {
521521
)
522522

523523
DiagnosticsEngineTester(diagnostics) { result in
524-
result.check(diagnostic: "product dependency 'Barx' not found", behavior: .error, location: "'Foo' /Foo")
524+
result.check(diagnostic: "Product 'Barx' not found. It is required by target 'Foo'.", behavior: .error, location: "'Foo' /Foo")
525525
}
526526
}
527527

Tests/PackageLoadingTests/PD4_2LoadingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class PackageDescription4_2LoadingTests: XCTestCase {
420420
try loadManifestThrowing(stream.bytes) { _ in }
421421
XCTFail("Unexpected success")
422422
} catch ManifestParseError.runtimeManifestErrors(let errors) {
423-
XCTAssertEqual(errors, ["Invalid version string: 1.0,0"])
423+
XCTAssertEqual(errors, ["Invalid semantic version string '1.0,0'"])
424424
}
425425
}
426426

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ class PackageBuilderTests: XCTestCase {
734734
]
735735
)
736736
PackageBuilderTester(manifest, in: fs) { result in
737-
result.checkDiagnostic("could not find source files for target(s): Random; use the 'path' property in the Swift 4 manifest to set a custom target path")
737+
result.checkDiagnostic("Source files for target Random should be located under 'Sources/Random', or a custom sources path can be set with the 'path' property in Package.swift")
738738
}
739739
}
740740

@@ -749,7 +749,7 @@ class PackageBuilderTests: XCTestCase {
749749
]
750750
)
751751
PackageBuilderTester(manifest, in: fs) { result in
752-
result.checkDiagnostic("could not find source files for target(s): Foo; use the 'path' property in the Swift 4 manifest to set a custom target path")
752+
result.checkDiagnostic("Source files for target Foo should be located under 'Sources/Foo', or a custom sources path can be set with the 'path' property in Package.swift")
753753
}
754754
}
755755

@@ -779,7 +779,7 @@ class PackageBuilderTests: XCTestCase {
779779
]
780780
)
781781
PackageBuilderTester(manifest, in: fs) { result in
782-
result.checkDiagnostic("could not find source files for target(s): foo; use the 'path' property in the Swift 4 manifest to set a custom target path")
782+
result.checkDiagnostic("Source files for target foo should be located under 'Sources/foo', or a custom sources path can be set with the 'path' property in Package.swift")
783783
}
784784
}
785785

@@ -829,7 +829,7 @@ class PackageBuilderTests: XCTestCase {
829829
]
830830
)
831831
PackageBuilderTester(manifest, in: fs) { result in
832-
result.checkDiagnostic("target 'pkg2' in package 'pkg' contains no valid source files")
832+
result.checkDiagnostic("Source files for target pkg2 should be located under /Sources/pkg2")
833833
result.checkModule("pkg1") { moduleResult in
834834
moduleResult.check(c99name: "pkg1", type: .library)
835835
moduleResult.checkSources(root: "/Sources/pkg1", paths: "Foo.swift")
@@ -1058,7 +1058,7 @@ class PackageBuilderTests: XCTestCase {
10581058
)
10591059

10601060
PackageBuilderTester(manifest, in: fs) { result in
1061-
result.checkDiagnostic("could not find source files for target(s): Bar; use the 'path' property in the Swift 4 manifest to set a custom target path")
1061+
result.checkDiagnostic("Source files for target Bar should be located under 'Sources/Bar', or a custom sources path can be set with the 'path' property in Package.swift")
10621062
}
10631063
}
10641064

@@ -1077,7 +1077,7 @@ class PackageBuilderTests: XCTestCase {
10771077
]
10781078
)
10791079
PackageBuilderTester(manifest, in: fs) { result in
1080-
result.checkDiagnostic("could not find source files for target(s): BarTests; use the 'path' property in the Swift 4 manifest to set a custom target path")
1080+
result.checkDiagnostic("Source files for target BarTests should be located under 'Sources/BarTests', or a custom sources path can be set with the 'path' property in Package.swift")
10811081
}
10821082

10831083
// We should be able to fix this by using custom paths.

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ final class WorkspaceTests: XCTestCase {
743743
]
744744
workspace.checkPackageGraph(deps: deps) { (_, diagnostics) in
745745
DiagnosticsEngineTester(diagnostics) { result in
746-
result.check(diagnostic: .contains("dependency graph is unresolvable;"), behavior: .error)
746+
result.check(diagnostic: .contains("the package dependency graph could not be resolved; possibly because of these requirements"), behavior: .error)
747747
}
748748
}
749749
// There should be no extra fetches.

0 commit comments

Comments
 (0)