Use colon more consistently in error messages (#3788)

Make the error messages more consistent with the format use elsewhere.
Split out from https://github.com/astral-sh/uv/pull/3705
This commit is contained in:
konsti 2024-05-23 14:33:21 +02:00 committed by GitHub
parent 9b870f20f1
commit 2a17309782
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 22 deletions

View File

@ -680,7 +680,7 @@ mod test {
path.as_ref(), path.as_ref(),
PreviewMode::Enabled, PreviewMode::Enabled,
) )
.with_context(|| format!("Failed to parse `{}`", path.user_display())) .with_context(|| format!("Failed to parse: `{}`", path.user_display()))
} }
fn format_err(input: &str) -> String { fn format_err(input: &str) -> String {
@ -709,7 +709,7 @@ mod test {
"#}; "#};
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: Failed to parse entry for: `tqdm` Caused by: Failed to parse entry for: `tqdm`
Caused by: Can't combine URLs from both `project.dependencies` and `tool.uv.sources` Caused by: Can't combine URLs from both `project.dependencies` and `tool.uv.sources`
"###); "###);
@ -730,7 +730,7 @@ mod test {
"#}; "#};
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: Failed to parse entry for: `tqdm` Caused by: Failed to parse entry for: `tqdm`
Caused by: Can only specify one of rev, tag, or branch Caused by: Can only specify one of rev, tag, or branch
"###); "###);
@ -752,7 +752,7 @@ mod test {
// TODO(konsti): This should tell you the set of valid fields // TODO(konsti): This should tell you the set of valid fields
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 9, column 8 Caused by: TOML parse error at line 9, column 8
| |
9 | tqdm = { git = "https://github.com/tqdm/tqdm", ref = "baaaaaab" } 9 | tqdm = { git = "https://github.com/tqdm/tqdm", ref = "baaaaaab" }
@ -778,7 +778,7 @@ mod test {
// TODO(konsti): This should tell you the set of valid fields // TODO(konsti): This should tell you the set of valid fields
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 9, column 8 Caused by: TOML parse error at line 9, column 8
| |
9 | tqdm = { path = "tqdm", index = "torch" } 9 | tqdm = { path = "tqdm", index = "torch" }
@ -817,7 +817,7 @@ mod test {
"#}; "#};
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 9, column 16 Caused by: TOML parse error at line 9, column 16
| |
9 | tqdm = { url = invalid url to tqdm-4.66.0-py3-none-any.whl" } 9 | tqdm = { url = invalid url to tqdm-4.66.0-py3-none-any.whl" }
@ -843,7 +843,7 @@ mod test {
"#}; "#};
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 9, column 8 Caused by: TOML parse error at line 9, column 8
| |
9 | tqdm = { url = "§invalid#+#*Ä" } 9 | tqdm = { url = "§invalid#+#*Ä" }
@ -868,7 +868,7 @@ mod test {
"#}; "#};
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: Failed to parse entry for: `tqdm` Caused by: Failed to parse entry for: `tqdm`
Caused by: Can't combine URLs from both `project.dependencies` and `tool.uv.sources` Caused by: Can't combine URLs from both `project.dependencies` and `tool.uv.sources`
"###); "###);
@ -889,7 +889,7 @@ mod test {
"#}; "#};
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: Failed to parse entry for: `tqdm` Caused by: Failed to parse entry for: `tqdm`
Caused by: Package is not included as workspace package in `tool.uv.workspace` Caused by: Package is not included as workspace package in `tool.uv.workspace`
"###); "###);
@ -910,7 +910,7 @@ mod test {
"#}; "#};
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: pyproject.toml section is declared as dynamic, but must be static: `project.dependencies` Caused by: pyproject.toml section is declared as dynamic, but must be static: `project.dependencies`
"###); "###);
} }
@ -923,7 +923,7 @@ mod test {
"}; "};
assert_snapshot!(format_err(input), @r###" assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: Must specify a `[project]` section alongside `[tool.uv.sources]` Caused by: Must specify a `[project]` section alongside `[tool.uv.sources]`
"###); "###);
} }

View File

@ -65,7 +65,7 @@ impl RequirementsSpecification {
Ok(match source { Ok(match source {
RequirementsSource::Package(name) => { RequirementsSource::Package(name) => {
let requirement = RequirementsTxtRequirement::parse(name, std::env::current_dir()?) let requirement = RequirementsTxtRequirement::parse(name, std::env::current_dir()?)
.with_context(|| format!("Failed to parse `{name}`"))?; .with_context(|| format!("Failed to parse: `{name}`"))?;
Self { Self {
requirements: vec![UnresolvedRequirementSpecification::try_from( requirements: vec![UnresolvedRequirementSpecification::try_from(
RequirementEntry { RequirementEntry {
@ -78,7 +78,7 @@ impl RequirementsSpecification {
} }
RequirementsSource::Editable(name) => { RequirementsSource::Editable(name) => {
let requirement = EditableRequirement::parse(name, None, std::env::current_dir()?) let requirement = EditableRequirement::parse(name, None, std::env::current_dir()?)
.with_context(|| format!("Failed to parse `{name}`"))?; .with_context(|| format!("Failed to parse: `{name}`"))?;
Self { Self {
editables: vec![requirement], editables: vec![requirement],
..Self::default() ..Self::default()
@ -122,7 +122,7 @@ impl RequirementsSpecification {
RequirementsSource::PyprojectToml(path) => { RequirementsSource::PyprojectToml(path) => {
let contents = uv_fs::read_to_string(&path).await?; let contents = uv_fs::read_to_string(&path).await?;
Self::parse_direct_pyproject_toml(&contents, extras, path.as_ref(), preview) Self::parse_direct_pyproject_toml(&contents, extras, path.as_ref(), preview)
.with_context(|| format!("Failed to parse `{}`", path.user_display()))? .with_context(|| format!("Failed to parse: `{}`", path.user_display()))?
} }
RequirementsSource::SetupPy(path) | RequirementsSource::SetupCfg(path) => Self { RequirementsSource::SetupPy(path) | RequirementsSource::SetupCfg(path) => Self {
source_trees: vec![path.clone()], source_trees: vec![path.clone()],

View File

@ -152,9 +152,9 @@ pub enum WorkspaceError {
#[error(transparent)] #[error(transparent)]
Io(#[from] std::io::Error), Io(#[from] std::io::Error),
#[error("Failed to parse `{0}`")] #[error("Failed to parse: `{0}`")]
PyprojectToml(String, #[source] toml::de::Error), PyprojectToml(String, #[source] toml::de::Error),
#[error("Failed to parse `{0}`")] #[error("Failed to parse: `{0}`")]
UvToml(String, #[source] toml::de::Error), UvToml(String, #[source] toml::de::Error),
} }

View File

@ -765,7 +765,7 @@ dependencies = [
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 5, column 8 Caused by: TOML parse error at line 5, column 8
| |
5 | name = "!project" 5 | name = "!project"

View File

@ -144,7 +144,7 @@ fn invalid_pyproject_toml_syntax() -> Result<()> {
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 1, column 5 Caused by: TOML parse error at line 1, column 5
| |
1 | 123 - 456 1 | 123 - 456
@ -171,7 +171,7 @@ fn invalid_pyproject_toml_schema() -> Result<()> {
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 1, column 1 Caused by: TOML parse error at line 1, column 1
| |
1 | [project] 1 | [project]
@ -209,7 +209,7 @@ dependencies = ["flask==1.0.x"]
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: after parsing '1.0', found '.x', which is not part of a valid version Caused by: after parsing '1.0', found '.x', which is not part of a valid version
flask==1.0.x flask==1.0.x
^^^^^^^ ^^^^^^^
@ -5014,7 +5014,7 @@ fn tool_uv_sources_is_in_preview() -> Result<()> {
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
error: Failed to parse `pyproject.toml` error: Failed to parse: `pyproject.toml`
Caused by: Failed to parse entry for: `tqdm` Caused by: Failed to parse entry for: `tqdm`
Caused by: `tool.uv.sources` is a preview feature; use `--preview` or set `UV_PREVIEW=1` to enable it Caused by: `tool.uv.sources` is a preview feature; use `--preview` or set `UV_PREVIEW=1` to enable it
"### "###

View File

@ -92,7 +92,7 @@ fn invalid_requirement() -> Result<()> {
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
error: Failed to parse `flask==1.0.x` error: Failed to parse: `flask==1.0.x`
Caused by: after parsing '1.0', found '.x', which is not part of a valid version Caused by: after parsing '1.0', found '.x', which is not part of a valid version
flask==1.0.x flask==1.0.x
^^^^^^^ ^^^^^^^