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

Don’t swallow virtual manifest parsing errors #4828

Merged
merged 1 commit into from
Dec 18, 2017

Conversation

SimonSapin
Copy link
Contributor

Before this change, cargo::util::toml::do_read_manifest ended like this:

    return match TomlManifest::to_real_manifest(/* … */) {
        Ok(/* … */) => /* … */,
        Err(e) => match TomlManifest::to_virtual_manifest(/* … */) {
            Ok(/* … */) => /* … */,
            Err(..) => Err(e),
        }
    };

Errors returned by to_virtual_manifest were always ignored. As a result, when something was wrong in a virtual manifest, Cargo would unhelpfully exit with no more output than:

error: failed to parse manifest at `/tmp/a/Cargo.toml`

Caused by:
  no `package` section found.

http://doc.crates.io/manifest.html#virtual-manifest defines a virtual manifest as “the package table is not present”, so let’s first determine if a manifest is virtual based on that criteria, and then only call one of the two methods.

Although it is not mentioned in the documentation, [project] seems to be in the code an alias for [package]. So let’s preserve that here too.

Before this change, `cargo::util::toml::do_read_manifest` ended like this:

```rust
    return match TomlManifest::to_real_manifest(/* … */) {
        Ok(/* … */) => /* … */,
        Err(e) => match TomlManifest::to_virtual_manifest(/* … */) {
            Ok(/* … */) => /* … */,
            Err(..) => Err(e),
        }
    };
```

Errors returned by `to_virtual_manifest` were always ignored.
As a result, when something was wrong in a virtual manifest,
Cargo would unhelpfully exit with no more output than:

```
error: failed to parse manifest at `/tmp/a/Cargo.toml`

Caused by:
  no `package` section found.
```

http://doc.crates.io/manifest.html#virtual-manifest defines
a virtual manifest as “the `package` table is not present”,
so let’s first determine if a manifest is virtual based
on that criteria, and then only call one of the two methods.

Although it is not mentioned in the documentation,
`[project]` seems to be in the code an alias for `[package]`.
So let’s preserve that here too.
@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@SimonSapin
Copy link
Contributor Author

By the way, this is unrelated to the point of this PR but the code being modified also implements a “unused manifest key”, but only for non-virtual manifest. Is there a reason for that, or should the warning also apply to virtual manifests?

@alexcrichton
Copy link
Member

@bors: r+

Looks great, thanks!

Also yeah seems plausible to me to warn about unused keys on virtual manifests as well!

@bors
Copy link
Collaborator

bors commented Dec 18, 2017

📌 Commit 3e06033 has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Dec 18, 2017

⌛ Testing commit 3e06033 with merge 510cf5e...

bors added a commit that referenced this pull request Dec 18, 2017
Don’t swallow virtual manifest parsing errors

Before this change, `cargo::util::toml::do_read_manifest` ended like this:

```rust
    return match TomlManifest::to_real_manifest(/* … */) {
        Ok(/* … */) => /* … */,
        Err(e) => match TomlManifest::to_virtual_manifest(/* … */) {
            Ok(/* … */) => /* … */,
            Err(..) => Err(e),
        }
    };
```

Errors returned by `to_virtual_manifest` were always ignored. As a result, when something was wrong in a virtual manifest, Cargo would unhelpfully exit with no more output than:

```
error: failed to parse manifest at `/tmp/a/Cargo.toml`

Caused by:
  no `package` section found.
```

http://doc.crates.io/manifest.html#virtual-manifest defines a virtual manifest as “the `package` table is not present”, so let’s first determine if a manifest is virtual based on that criteria, and then only call one of the two methods.

Although it is not mentioned in the documentation, `[project]` seems to be in the code an alias for `[package]`. So let’s preserve that here too.
@bors
Copy link
Collaborator

bors commented Dec 18, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 510cf5e to master...

@bors bors merged commit 3e06033 into rust-lang:master Dec 18, 2017
@ehuss ehuss added this to the 1.24.0 milestone Feb 6, 2022
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.

5 participants