-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Index parsing errors are swallowed #14894
Comments
This is heavily related to #10623. Ideally we track the error state through Cargo. We've added What is distinct about this Issue compared to #10623 is adding an error variant for when the parse fails for a reason other than a newer index version. Granted, this will only help if we can extract the name and version. If its too corrupted to even do that, we'll need to consider other means of reporting. |
Thanks for the report! The failures are silenced somewhat on purpose, since this is intended to handle the scenario where an older version doesn't understand the format of newer index entries. We wanted to avoid the situation where older versions would spam warnings on the console whenever they are used. I think this is somewhat related or a duplicate of #7929 where we could have a controlled method of presenting this information. Or maybe similarly to #4309, where there could be a separate command to display that. |
I think there are two separate cases
The work we have planned for #10623 would make it so we have more information available to show for #7929. |
…14923) ### What does this PR try to resolve? The user likely intended what they said and we should tell them why it didn't work. Rejected versions also imply alt versions below them. Fixes #4260 In changing the errors from alt-versions to rejected-versions, I found part of the old error message was better and changed the message introduced in #14897 from matching alt-names to alt-versions. This includes the test for #14921. The "fix" was done before this because as it was part of the refactors in prep for this. ### How should we test and review this PR? ### Additional information Next steps after this are to still produce an `IndexSummary::Unsupported` even if there are deserialization errors, so long as we know the name and version which should take care of #10623 and #14894.
While rust-lang#14897 reported packages with an unsupported index schema version, that only worked if the changes in the schema version did not cause errors in deserializing `IndexPackage` or in generating a `Summary`. This extends that change by recoverying on error with a more lax, incomplete parse of `IndexPackage` which should always generate a valid `Summary`. To help with a buggy Index, we also will report as many as we can. This does not provide a way to report to users or log on cache reads if the index entry is not at least `{"name": "<string>", "vers": "<semver>"}`. As a side effect, the index cache will include more "invalid" index entries. That should be ok as we will ignore the invalid entry in the cache when loading it. Ignoring of invalid entries dates back to rust-lang#6880 when the index cache was introduced. Fixes rust-lang#10623 Fixes rust-lang#14894
While rust-lang#14897 reported packages with an unsupported index schema version, that only worked if the changes in the schema version did not cause errors in deserializing `IndexPackage` or in generating a `Summary`. This extends that change by recoverying on error with a more lax, incomplete parse of `IndexPackage` which should always generate a valid `Summary`. To help with a buggy Index, we also will report as many as we can. This does not provide a way to report to users or log on cache reads if the index entry is not at least `{"name": "<string>", "vers": "<semver>"}`. As a side effect, the index cache will include more "invalid" index entries. That should be ok as we will ignore the invalid entry in the cache when loading it. Ignoring of invalid entries dates back to rust-lang#6880 when the index cache was introduced. Fixes rust-lang#10623 Fixes rust-lang#14894
### What does this PR try to resolve? While #14897 reported packages with an unsupported index schema version, that only worked if the changes in the schema version did not cause errors in deserializing `IndexPackage` or in generating a `Summary`. This extends that change by recoverying on error with a more lax, incomplete parse of `IndexPackage` which should always generate a valid `Summary`. To help with a buggy Index, we also will report as many as we can. This does not provide a way to report to users or log on cache reads if the index entry is not at least `{"name": "<string>", "vers": "<semver>"}`. Fixes #10623 Fixes #14894 ### How should we test and review this PR? My biggest paranoia is some bad interaction with the index cache including more "invalid" index entries. That should be ok as we will ignore the invalid entry in the cache when loading it. Ignoring of invalid entries dates back to #6880 when the index cache was introduced. ### Additional information
Problem
When using a private registry, I recently ran into a case where a crate version that is in the index (confirmed by cURLing the registry directly) could not be resolved by Cargo, giving me an error like
I quickly suspected that the index entry was invalid somehow, but Cargo gave no errors or warnings, even with
CARGO_LOG=trace
. Furthermore, by tweakinghttp_remote.rs
, I found that its query to the registry (with anif-none-match
header) returnedNotModified
, indicating Cargo did have the etag of the latest index file, which did include the crate/version in question. By removing the etag header, I also confirmed that the contents Cargo got from its request contained the version in question.Long story short, I discovered that Cargo ends up swallowing errors related to invalid index entries. The first time Cargo downloads an index file with an invalid entry, it hits
cargo/src/cargo/core/summary.rs
Lines 345 to 348 in 05f54fd
However, that gets turned into a
tracing::info
incargo/src/cargo/sources/registry/index/mod.rs
Lines 604 to 619 in 05f54fd
The user is likely to miss this since Cargo tracing logs are off by default, so they will just observe that Cargo claims the version doesn't exist.
Unfortunately, the issue doesn't stop there. If the user then tries to run with
CARGO_LOG=trace
, they will then see no errors or warnings from Cargo. In fact, the logs will make it seem like the invalid entry doesn't exist at all. There will be no trace of it anywhere. This is because when Cargo parses an index entry, it caches the parsed lines so that it doesn't have to parse them againcargo/src/cargo/sources/registry/index/mod.rs
Line 622 in 05f54fd
cargo/src/cargo/sources/registry/index/mod.rs
Lines 627 to 631 in 05f54fd
However, when a line can't be parsed, it doesn't cache that line (note the
continue
where the error gets turned intotracing::info!
). It also doesn't leave that line as "unparsed" somewhere. So on subsequent invocations, Cargo grabs the version list from the cache manager to avoid parsing lines again, doesn't observe the (invalid) index entry for the version in question so it doesn't warn, then downloads the file again because it doesn't find the requested version, that download yields and empty response because the etag does match the latest index file, and so Cargo gives up.So, two requests:
Steps
cargo build
.cargo build
withCARGO_LOG=trace
.Possible Solution(s)
No response
Notes
In my case, the index entry parsing error I was eventually able to extract by disabling the
if-none-match
logic and then running withCARGO_LOG=trace
was:I suspect, but am not quite sure, that this may be an erroneous index entry manipulation by the private registry provider we're using. Although it could also be that
cargo publish
allowed publishing something with a nonsensical optional dependency in the first place?Version
The text was updated successfully, but these errors were encountered: