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

Improve error message displayed when a string is used instead of an array for 'authors' in the manifest #10942

Closed
ptdecker opened this issue Aug 5, 2022 · 2 comments · Fixed by #10944
Labels
A-manifest Area: Cargo.toml issues C-bug Category: bug

Comments

@ptdecker
Copy link
Contributor

ptdecker commented Aug 5, 2022

Problem

Currently, if one uses a string instead of an array of strings as the value for the authors field an error message is displayed which is not helpful for a new Rust developer to identify the cause of the problem.

Example of an incorrect Cargo.toml:

[package]
name = "alenandbarb"
version = "0.1.0"
edition = "2021"
authors = "Todd Decker"
description = "A toy application for crustatian exploration along network and applications seafloor"

[features]
desktop = ["dioxus/desktop"]
web = ["dioxus/web"]

[dependencies]
dioxus = "0.2.4"

The error message displayed is:

Execution failed (exit code 101).
/Users/ptdecker/.cargo/bin/cargo metadata --verbose --format-version 1 --all-features
stdout : error: failed to parse manifest at `/Users/ptdecker/CLionProjects/alenandbarb/Cargo.toml`

Caused by:
  data did not match any variant of untagged enum MaybeWorkspace for key `package.authors`

stderr : 

Proposed Solution

An error message along the lines of the below would be more informative:

Execution failed (exit code 101).
/Users/ptdecker/.cargo/bin/cargo metadata --verbose --format-version 1 --all-features
stdout : error: failed to parse manifest at `/Users/ptdecker/CLionProjects/alenandbarb/Cargo.toml`

Caused by:
  value of `package.authors` is a string, while an array was expected

stderr : 

Notes

I also submitted the PR below to update the Cargo documentation to better explain the requirements of the field:

#10938

@epage saw my post on the forum about my problem (link) and suggested that I also submit an issue to improve the error message itself.

Thank you

P. Todd Decker

@ptdecker ptdecker added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Aug 5, 2022
@epage epage added C-bug Category: bug A-manifest Area: Cargo.toml issues E-help-wanted and removed C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Aug 5, 2022
@Rustin170506
Copy link
Member

For now, I think it's challenging to improve it because the internal error will ignore by MaybeWorkspace.
Also, publish: Option<MaybeWorkspace<VecStringOrBool>> affect by it, you can not get the VecStringOrBool inner error.

[package]
name = "cargo"
version = "0.65.0"
edition = "2021"
license = "MIT OR Apache-2.0"
homepage = "https://crates.io"
repository = "https://github.com/rust-lang/cargo"
documentation = "https://docs.rs/cargo"
readme = "README.md"
description = """
Cargo, a package manager for Rust.
"""
publish = "a"
➜  cargo git:(master) ✗ ./target/debug/cargo test
error: failed to parse manifest at `/Users/rustin/ClionProjects/cargo/Cargo.toml`

Caused by:
  data did not match any variant of untagged enum MaybeWorkspace for key `package.publish`

It should be invalid type: string "a", expected a boolean or vector of strings.

See more: serde-rs/serde#1544.

@epage Do you have any thoughts about how to work around it?

@Rustin170506
Copy link
Member

I saw #10944 try to fix it. Maybe it's a good way.

@bors bors closed this as completed in 9809f8f Aug 16, 2022
bors added a commit that referenced this issue Sep 22, 2022
Improve errors for TOML fields that support workspace inheritance

Fixes #10997

This also addresses the issue with `MaybeWorkspace<VecStringOrBool>` mentioned in #10942:

```
Caused by:
  invalid type: string "foo", expected a boolean or vector of strings for key `package.publish`
```

I removed the `maybe_workspace_vec_string` deserializer in 7a50c0c because the error message from the inner `Vec<String>` is now surfaced, but I can revert that if it's preferable to keep those changes.

I tried to base the `deserialize` implementation off of the derived impl for an untagged enum from `cargo expand`. This approach [ultimately led me](https://github.com/serde-rs/serde/blob/v1.0.144/serde/src/private/de.rs#L218) to adding the `serde-value` dependency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-manifest Area: Cargo.toml issues C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants