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

Add detailed errors for tool.uv.sources deserialization failures #7823

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions crates/uv-distribution/src/metadata/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ impl LoweredRequirement {
};
(source, marker)
}
Source::CatchAll { .. } => {
// Emit a dedicated error message, which is an improvement over Serde's default error.
return Err(LoweringError::InvalidEntry);
}
};

marker.and(requirement.marker.clone());
Expand Down Expand Up @@ -325,11 +321,6 @@ impl LoweredRequirement {
Source::Workspace { .. } => {
return Err(LoweringError::WorkspaceMember);
}
Source::CatchAll { .. } => {
// Emit a dedicated error message, which is an improvement over Serde's default
// error.
return Err(LoweringError::InvalidEntry);
}
};

marker.and(requirement.marker.clone());
Expand Down Expand Up @@ -364,8 +355,6 @@ pub enum LoweringError {
UndeclaredWorkspacePackage,
#[error("Can only specify one of: `rev`, `tag`, or `branch`")]
MoreThanOneGitRef,
#[error("Unable to combine options in `tool.uv.sources`")]
InvalidEntry,
#[error("Workspace members are not allowed in non-workspace contexts")]
WorkspaceMember,
#[error(transparent)]
Expand Down
22 changes: 11 additions & 11 deletions crates/uv-distribution/src/metadata/requires_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ mod test {
8 | tqdm = true
| ^^^^
invalid type: boolean `true`, expected an array or map

"###);
}

Expand All @@ -263,8 +262,12 @@ mod test {
"#};

assert_snapshot!(format_err(input).await, @r###"
error: Failed to parse entry for: `tqdm`
Caused by: Can only specify one of: `rev`, `tag`, or `branch`
error: TOML parse error at line 8, column 8
|
8 | tqdm = { git = "https://github.com/tqdm/tqdm", rev = "baaaaaab", tag = "v1.0.0" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
expected at most one of `rev`, `tag`, or `branch`

"###);
}

Expand All @@ -281,14 +284,12 @@ mod test {
tqdm = { git = "https://github.com/tqdm/tqdm", ref = "baaaaaab" }
"#};

// TODO(konsti): This should tell you the set of valid fields
assert_snapshot!(format_err(input).await, @r###"
error: TOML parse error at line 8, column 8
|
8 | tqdm = { git = "https://github.com/tqdm/tqdm", ref = "baaaaaab" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data did not match any variant of untagged enum Source

unknown field `ref`, expected one of `git`, `subdirectory`, `rev`, `tag`, `branch`, `url`, `path`, `editable`, `index`, `workspace`, `marker`
"###);
}

Expand All @@ -305,14 +306,12 @@ mod test {
tqdm = { path = "tqdm", index = "torch" }
"#};

// TODO(konsti): This should tell you the set of valid fields
assert_snapshot!(format_err(input).await, @r###"
error: TOML parse error at line 8, column 8
|
8 | tqdm = { path = "tqdm", index = "torch" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data did not match any variant of untagged enum Source

cannot specify both `path` and `index`
"###);
}

Expand Down Expand Up @@ -349,7 +348,6 @@ mod test {
| ^
invalid string
expected `"`, `'`

"###);
}

Expand All @@ -371,8 +369,10 @@ mod test {
|
8 | tqdm = { url = "§invalid#+#*Ä" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
data did not match any variant of untagged enum Source
invalid value: string "§invalid#+#*Ä", expected relative URL without a base


in `url`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part I don't quite understand. It looks like dtolnay/serde-untagged#2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really bothering me...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah annoying, but still an improvement. :)

A solution here isn't obvious to me. (Other than hand-rolling a Deserialize impl.)

"###);
}

Expand Down
Loading
Loading