Skip to content
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

consistently add context with file path when parsing fails #3853

Merged
merged 3 commits into from
Jun 3, 2024

Conversation

Skgland
Copy link
Contributor

@Skgland Skgland commented Jun 2, 2024

fixes #3851

@rami3l
Copy link
Member

rami3l commented Jun 2, 2024

@Skgland Thanks for making this PR!

Would you mind explain in detail what is the motivation of this PR and what has been improved with a simple before/after comparison, for example?

PS: To make sure we are on the same page, regarding #3851 I would like to underline that the server incident causing bad manifests being downloaded is probably out of the scope of the Rustup project (so it possibly cannot be "fixed"), although improvements regarding error handling are welcomed.

@rami3l
Copy link
Member

rami3l commented Jun 2, 2024

Your CI failure is #3852, we will be investigating this on our side.

@Skgland
Copy link
Contributor Author

Skgland commented Jun 2, 2024

Would you mind explain in detail what is the motivation of this PR and what has been improved with a simple before/after comparison, for example?

Having a manifest parsing error while using cargo I initially assumed a mistake in the Cargo.toml,
though due to the problematic line in the error message that was quickly ruled out.
Next I tried to figure out where cargo was trying and failing to parse a manifest.
I assumed that this was maybe a manifest from the crates.io package registry cache, but searching for the line in ~/.cargo/ didn't bring up any results.
Only when I noticed rust-analyzer and cargo --help fail the same way did I come to the conclusion that the source is likely from the rustup wrapper of those binaries and not cargo itself and as such began searching in rustup.
This search could have been shorten had the manifest path been part of the error message, thus me not having to search for which file it was that had the error.

To recreate the error condition I inserted a NUL byte in a valid manifest file, resulting in the following error before/after my change.

Before:

$> RUSTUP_HOME=home CARGO_HOME=home home/bin/cargo --help
error: error parsing manifest: TOML parse error at line 1286, column 24
     |
1286 | [[pkg.rust.target.aarch64-apple-darwin.components]]
     |                        ^
invalid table header
expected `.`, `]]`

After:

$> RUSTUP_HOME=home CARGO_HOME=home home/bin/cargo --help
error: could not parse manifest file: '/home/bennet/git/rustup/home/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/multirust-channel-manifest.toml': error parsing manifest: TOML parse error at line 1286, column 24
     |
1286 | [[pkg.rust.target.aarch64-apple-darwin.components]]
     |                        ^
invalid table header
expected `.`, `]]`

PS: To make sure we are on the same page, regarding #3851 I would like to underline that the server incident causing bad manifests being downloaded is probably out of the scope of the Rustup project (so it possibly cannot be "fixed"), although improvements regarding error handling are welcomed.

Yes, I agree that the source of the manifest corruption is outside of rustup and as such out of scope. My goal with the Issue and this PR was to improve the error reporting. Also, I am pretty sure that there was no server incident involved, but I believe that the export and re-import of the WSL 2 distribution somehow corrupted the disk image file, resulting in the already installed manifest getting corrupted.

@rami3l
Copy link
Member

rami3l commented Jun 2, 2024

@Skgland Thanks for the clarification!

At Rustup the word "manifest" is used specifically to refer to a certain kind of file downloaded from the Rustup release server, and, as you've found out, named multirust-channel-manifest.toml.

This file is specifically used to determine what are available in this channel, however I have no idea how you got that wrong (since we have shasum checks), sorry about that...

#[test]
fn bad_sha_on_manifest() {
setup(&|config| {
// Corrupt the sha
let sha_file = config
.distdir
.as_ref()
.unwrap()
.join("dist/channel-rust-nightly.toml.sha256");
let sha_str = fs::read_to_string(&sha_file).unwrap();
let mut sha_bytes = sha_str.into_bytes();
sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa");
let sha_str = String::from_utf8(sha_bytes).unwrap();
rustup::utils::raw::write_file(&sha_file, &sha_str).unwrap();
// We fail because the sha is bad, but we should emit the special message to that effect.
config.expect_err(
&["rustup", "default", "nightly"],
"update not yet available",
);
});
}

This PR might have to wait for #3852 before we get our merge CI green again. If you'd like, in the meantime, you can add a regression test in the file above.

@Skgland
Copy link
Contributor Author

Skgland commented Jun 2, 2024

Ok, just pushed a commit with a regression test

@Skgland
Copy link
Contributor Author

Skgland commented Jun 2, 2024

Hm, looks like my regression test fails on windows due to \ vs. / in the path in the error message.

@Skgland
Copy link
Contributor Author

Skgland commented Jun 2, 2024

Do you have a suggestion for how to deal with the path-separator discrepancy on windows or should I skip the test on windows with e.g. #[cfg(not(target_os = "windows"))] the test?

@rami3l
Copy link
Member

rami3l commented Jun 2, 2024

Do you have a suggestion for how to deal with the path-separator discrepancy on windows or should I skip the test on windows with e.g. #[cfg(not(target_os = "windows"))] the test?

@Skgland Please feel free to use what you consider appropriate for the problem. For example you can use two conditionally compiled assertions for Windows and Unix. Or you can compare the path components.

@rami3l rami3l added this pull request to the merge queue Jun 3, 2024
Merged via the queue into rust-lang:master with commit 73c6b19 Jun 3, 2024
22 checks passed
@Skgland Skgland deleted the path-for-parse-error branch June 3, 2024 07:39
@rami3l rami3l mentioned this pull request Oct 6, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

all cargo commands error, because some manifest is broken
2 participants