2920: Better handle illformed node id from metadata r=matklad a=edwin0cheng

In some rare cases, deps node-id from cargo-metadata do not match its version-id, which cause a panic in `cargo-workspace.rs`. This PR try to ignore these ill-formed node id from `cargo-metadata`. An alternative is return  `Err` in these cases but I think make it resilience is a better choice here.

Related #2767

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
bors[bot] 2020-01-30 16:48:35 +00:00 committed by GitHub
commit c7e0baf1a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -207,9 +207,25 @@ impl CargoWorkspace {
}
let resolve = meta.resolve.expect("metadata executed with deps");
for node in resolve.nodes {
let source = pkg_by_id[&node.id];
let source = match pkg_by_id.get(&node.id) {
Some(&src) => src,
None => {
log::error!("Node id do not match in cargo metadata, ignoring {}", node.id);
continue;
}
};
for dep_node in node.deps {
let dep = PackageDependency { name: dep_node.name, pkg: pkg_by_id[&dep_node.pkg] };
let pkg = match pkg_by_id.get(&dep_node.pkg) {
Some(&pkg) => pkg,
None => {
log::error!(
"Dep node id do not match in cargo metadata, ignoring {}",
dep_node.pkg
);
continue;
}
};
let dep = PackageDependency { name: dep_node.name, pkg };
packages[source].dependencies.push(dep);
}
packages[source].features.extend(node.features);