-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve error message about the PackageGraphError.productDependencyNotFound #7419
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
Conversation
|
||
testDiagnostics(observability.diagnostics) { result in | ||
result.check( | ||
diagnostic: "product 'zzy' required by package 'aaa' target 'aaa' not found. Did you mean 'zzz'?", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR fix will cause the error message to include "Did you mean...".
Previously, this message was not displayed depending on the name of the package directory.
if dependencyProductInDecl { | ||
return "product '\(dependencyProductName)' is declared in the same package '\(package)' and can't be used as a dependency for target '\(targetName)'." | ||
} else { | ||
var description = "product '\(dependencyProductName)' required by package '\(package)' target '\(targetName)' \(dependencyPackageName.map{ "not found in package '\($0)'" } ?? "not found")." | ||
if let similarProductName { | ||
if let similarProductName, let packageContainingSimilarProduct { | ||
description += " Did you mean '.product(name: \"\(similarProductName)\", package: \"\(packageContainingSimilarProduct)\")'?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote the following test code to test the output of this message.
func test_() throws {
let fs = InMemoryFileSystem(emptyFiles:
"/zzz/Sources/zzz/main.swift",
"/aaa/Sources/aaa/source.swift"
)
let observability = ObservabilitySystem.makeForTesting()
let g = try loadModulesGraph(
fileSystem: fs,
manifests: [
Manifest.createRootManifest(
displayName: "zzz",
path: "/zzz",
dependencies: [
.remoteSourceControl(
url: "https://example.com/example.git",
requirement: .exact("1.3.0")
)
],
products: [],
targets: [
TargetDescription(
name: "zzz",
dependencies: ["aaa"],
type: .executable
)
]),
Manifest.createRemoteSourceControlManifest(
displayName: "aaa",
url: "https://example.com/example.git",
path: "/aaa",
version: "1.3.0",
products: [
ProductDescription(
name: "aaa",
type: .library(.automatic),
targets: ["aaa"]
)
],
targets: [
TargetDescription(name: "aaa")
]
)
],
observabilityScope: observability.topScope
)
testDiagnostics(observability.diagnostics) { result in
result.check(
diagnostic: "error: 'zzz': product 'aaa' required by package 'zzz' target 'repro' not found. Did you mean '.product(name: \"aaa\", package: \"aaa\")'?",
severity: .error
)
}
}
However, this test fails with the message "test_(): failed - No diagnostics left to check".
I would like to know how to solve this problem.
@swift-ci test |
Thank you for your contribution! |
…tFound (swiftlang#7419) Fixed a bug in the productDependencyNotFound error message ### Motivation: fix swiftlang#7398 The above issue suggests the following two defects. 1. package dependency resolution changes depending on the order of packages (alphabetical order) 2. the phrase "Did you meen..." in the error message in the error message is not on target. ### Modifications: The first problem is as described in the issue, if users rename the directory containing Package.swift from repro to zzz, the "Did you meen..." will appear. will appear. Essentially, the error minutes should be displayed in full, regardless of the name of the directory. This is due to the fact that the loop used to resolve dependencies depends on the alphabetical order of the directories and the side effect on allTargetName inside the loop. Therefore, the side effect for allTargetName inside the loop has been moved to the outside of the loop. The second problem is that when dependency A of a package is not found, a strange suggestion "Did you meen `A`? ", which is a strange suggestion. This is because when a dependency is not found, the message "Did you meen `<target name>`" is printed if there is a dependency with a similar name (even the exact same name). Thus, if the names are the same, "Did you meen `.product(name: ... , package: "swift-argugument")"`" instead of the found target name. ### Result: Command to execute: `swift build` Result of command:. `error: 'repro': product 'ArgumentParser' required by package 'repro' target 'repro' not found. Did you mean '.product(name: "ArgumentParser", package: "swift-argument-parser")'?` Condition: The following steps were taken to create the environment. 1. mkdir repro 1. cd repro 1. swift package init --type executable 1. Open Package.swift and make sure it has this content: ```swift // swift-tools-version: 5.10 import PackageDescription let package = Package( name: "repro", dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0") ], targets: [ .executableTarget( name: "repro", dependencies: ["ArgumentParser"] ) ] ) ``` --------- Co-authored-by: Yuta Saito <[email protected]>
…tFound (swiftlang#7419) Fixed a bug in the productDependencyNotFound error message ### Motivation: fix swiftlang#7398 The above issue suggests the following two defects. 1. package dependency resolution changes depending on the order of packages (alphabetical order) 2. the phrase "Did you meen..." in the error message in the error message is not on target. ### Modifications: The first problem is as described in the issue, if users rename the directory containing Package.swift from repro to zzz, the "Did you meen..." will appear. will appear. Essentially, the error minutes should be displayed in full, regardless of the name of the directory. This is due to the fact that the loop used to resolve dependencies depends on the alphabetical order of the directories and the side effect on allTargetName inside the loop. Therefore, the side effect for allTargetName inside the loop has been moved to the outside of the loop. The second problem is that when dependency A of a package is not found, a strange suggestion "Did you meen `A`? ", which is a strange suggestion. This is because when a dependency is not found, the message "Did you meen `<target name>`" is printed if there is a dependency with a similar name (even the exact same name). Thus, if the names are the same, "Did you meen `.product(name: ... , package: "swift-argugument")"`" instead of the found target name. ### Result: Command to execute: `swift build` Result of command:. `error: 'repro': product 'ArgumentParser' required by package 'repro' target 'repro' not found. Did you mean '.product(name: "ArgumentParser", package: "swift-argument-parser")'?` Condition: The following steps were taken to create the environment. 1. mkdir repro 1. cd repro 1. swift package init --type executable 1. Open Package.swift and make sure it has this content: ```swift // swift-tools-version: 5.10 import PackageDescription let package = Package( name: "repro", dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0") ], targets: [ .executableTarget( name: "repro", dependencies: ["ArgumentParser"] ) ] ) ``` --------- Co-authored-by: Yuta Saito <[email protected]>
…tFound (swiftlang#7419) Fixed a bug in the productDependencyNotFound error message ### Motivation: fix swiftlang#7398 The above issue suggests the following two defects. 1. package dependency resolution changes depending on the order of packages (alphabetical order) 2. the phrase "Did you meen..." in the error message in the error message is not on target. ### Modifications: The first problem is as described in the issue, if users rename the directory containing Package.swift from repro to zzz, the "Did you meen..." will appear. will appear. Essentially, the error minutes should be displayed in full, regardless of the name of the directory. This is due to the fact that the loop used to resolve dependencies depends on the alphabetical order of the directories and the side effect on allTargetName inside the loop. Therefore, the side effect for allTargetName inside the loop has been moved to the outside of the loop. The second problem is that when dependency A of a package is not found, a strange suggestion "Did you meen `A`? ", which is a strange suggestion. This is because when a dependency is not found, the message "Did you meen `<target name>`" is printed if there is a dependency with a similar name (even the exact same name). Thus, if the names are the same, "Did you meen `.product(name: ... , package: "swift-argugument")"`" instead of the found target name. ### Result: Command to execute: `swift build` Result of command:. `error: 'repro': product 'ArgumentParser' required by package 'repro' target 'repro' not found. Did you mean '.product(name: "ArgumentParser", package: "swift-argument-parser")'?` Condition: The following steps were taken to create the environment. 1. mkdir repro 1. cd repro 1. swift package init --type executable 1. Open Package.swift and make sure it has this content: ```swift // swift-tools-version: 5.10 import PackageDescription let package = Package( name: "repro", dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0") ], targets: [ .executableTarget( name: "repro", dependencies: ["ArgumentParser"] ) ] ) ``` --------- Co-authored-by: Yuta Saito <[email protected]> (cherry picked from commit ea1730b)
*Explanation*: I went through the last few months of PRs to make sure anything relevant is cherry-picked. Most of these are NFC but cherry-picking will help with conflicts. The main are: * Better error message - #7419 * Fix for visionOS for `--build-system xcode` - #7448 * Package registry fix - #7454 * Manifest editing API for adding target dependencies - #7552 * Various sendable annotations *Scope*: Package manifests/graphs with duplicate product/target names. *Risk*: Very low *Reviewed By*: Various, mostly @MaxDesiatov --------- Co-authored-by: Max Desiatov <[email protected]> Co-authored-by: k-kohey <[email protected]> Co-authored-by: miharu <[email protected]> Co-authored-by: Ryu <[email protected]> Co-authored-by: Philipp Wallrich <[email protected]> Co-authored-by: Boris Bügling <[email protected]> Co-authored-by: coffmark <[email protected]> Co-authored-by: Doug Gregor <[email protected]>
Fixed a bug in the productDependencyNotFound error message
Motivation:
fix #7398
The above issue suggests the following two defects.
Modifications:
The first problem is as described in the issue, if users rename the directory containing Package.swift from repro to zzz, the "Did you meen..." will appear. Essentially, the error minutes should be displayed in full, regardless of the name of the directory. This is due to the fact that the loop used to resolve dependencies depends on the alphabetical order of the directories and the side effect on allTargetName inside the loop. Therefore, the side effect for allTargetName inside the loop has been moved to the outside of the loop.
The second problem is that when dependency A of a package is not found, a strange suggestion "Did you meen
A
? ", which is a strange suggestion. This is because when a dependency is not found, the message "Did you meen<target name>
" is printed if there is a dependency with a similar name (even the exact same name). Thus, if the names are the same, "Did you meen.product(name: ... , package: "swift-argugument")"
" instead of the found target name.Result:
Command to execute:
swift build
Result of command:.
error: 'repro': product 'ArgumentParser' required by package 'repro' target 'repro' not found. Did you mean '.product(name: "ArgumentParser", package: "swift-argument-parser")'?
Condition:
The following steps were taken to create the environment.