-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #6157 - alexheretic:member-manifest-error, r=alexcrichton
Expose manifest error chain in CargoErrors Adds new `ManifestError`s to the `CargoError` causal chain. These errors pass on their display, but provide more detail on which manifests are at fault when failing to build a `Workspace`. This is useful for lib users, in particular rls, allowing lookup of a particular manifest file that caused the error. See #6144. For example a workspace _foo_ where a member _bar_ has an invalid toml manifest would have the error chain: - failed to parse manifest at `/home/alex/project/foo/bar/Cargo.toml` _ManifestError: /home/alex/project/foo/Cargo.toml_ - failed to parse manifest at `/home/alex/project/foo/bar/Cargo.toml` _ManifestError: /home/alex/project/foo/bar/Cargo.toml_ - failed to parse manifest at `/home/alex/project/foo/bar/Cargo.toml` - could not parse input as TOML - expected a value, found an equals at line 8 This will allow rls to point to a particular workspace member's manifest file when that manifest fails to deserialize, has invalid paths, etc. This change should not affect binary use.
- Loading branch information
Showing
6 changed files
with
178 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
use cargo::core::Workspace; | ||
use cargo::util::{config::Config, errors::ManifestError}; | ||
|
||
use support::project; | ||
|
||
/// Tests inclusion of a `ManifestError` pointing to a member manifest | ||
/// when that manifest fails to deserialize. | ||
#[test] | ||
fn toml_deserialize_manifest_error() { | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[project] | ||
name = "foo" | ||
version = "0.1.0" | ||
authors = [] | ||
[dependencies] | ||
bar = { path = "bar" } | ||
[workspace] | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.file( | ||
"bar/Cargo.toml", | ||
r#" | ||
[project] | ||
name = "bar" | ||
version = "0.1.0" | ||
authors = [] | ||
[dependencies] | ||
foobar == "0.55" | ||
"#, | ||
) | ||
.file("bar/src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
let root_manifest_path = p.root().join("Cargo.toml"); | ||
let member_manifest_path = p.root().join("bar").join("Cargo.toml"); | ||
|
||
let error = Workspace::new(&root_manifest_path, &Config::default().unwrap()).unwrap_err(); | ||
eprintln!("{:?}", error); | ||
|
||
let manifest_err: &ManifestError = error.downcast_ref().expect("Not a ManifestError"); | ||
assert_eq!(manifest_err.manifest_path(), &root_manifest_path); | ||
|
||
let causes: Vec<_> = manifest_err.manifest_causes().collect(); | ||
assert_eq!(causes.len(), 1, "{:?}", causes); | ||
assert_eq!(causes[0].manifest_path(), &member_manifest_path); | ||
} | ||
|
||
/// Tests inclusion of a `ManifestError` pointing to a member manifest | ||
/// when that manifest has an invalid dependency path. | ||
#[test] | ||
fn member_manifest_path_io_error() { | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[project] | ||
name = "foo" | ||
version = "0.1.0" | ||
authors = [] | ||
[dependencies] | ||
bar = { path = "bar" } | ||
[workspace] | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.file( | ||
"bar/Cargo.toml", | ||
r#" | ||
[project] | ||
name = "bar" | ||
version = "0.1.0" | ||
authors = [] | ||
[dependencies] | ||
foobar = { path = "nosuch" } | ||
"#, | ||
) | ||
.file("bar/src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
let root_manifest_path = p.root().join("Cargo.toml"); | ||
let member_manifest_path = p.root().join("bar").join("Cargo.toml"); | ||
let missing_manifest_path = p.root().join("bar").join("nosuch").join("Cargo.toml"); | ||
|
||
let error = Workspace::new(&root_manifest_path, &Config::default().unwrap()).unwrap_err(); | ||
eprintln!("{:?}", error); | ||
|
||
let manifest_err: &ManifestError = error.downcast_ref().expect("Not a ManifestError"); | ||
assert_eq!(manifest_err.manifest_path(), &root_manifest_path); | ||
|
||
let causes: Vec<_> = manifest_err.manifest_causes().collect(); | ||
assert_eq!(causes.len(), 2, "{:?}", causes); | ||
assert_eq!(causes[0].manifest_path(), &member_manifest_path); | ||
assert_eq!(causes[1].manifest_path(), &missing_manifest_path); | ||
} |