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

Better error message for missing space before semicolon in requirements #1746

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

konstin
Copy link
Member

@konstin konstin commented Feb 20, 2024

PEP 508 requires a space between a URL and the semicolon separating it from the markers to disambiguate it from a url ending with a semicolon. This is easy to get wrong because the space is not required after a plain name of PEP 440 specifier. The new error message explicitly points out the missing space.

Fixes #1637

PEP 508 requires a space between a URL and the semicolon separating it from the markers to disambiguate it from a url ending with a semicolon. This is easy to get wrong because the space is not required after a plain name of PEP 440 specifier. The new error message explicitly points out the missing space.

Fixes #1637.
@konstin konstin added the error messages Messaging when something goes wrong label Feb 20, 2024
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Nice!

// Unwrap safety: The `VerbatimUrl` we just parsed has a string source.
if url.given().unwrap().ends_with(';') && marker.is_none() {
return Err(Pep508Error {
message: Pep508ErrorSource::String("Missing space before ';'".to_string()),
Copy link
Member

Choose a reason for hiding this comment

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

This tells you what's gone wrong, but not why we need to issue an error here in the first place. I think if I were a user and I got this message, my immediate question would be, "Well, you obviously understood what I meant here... so why not just do that?"

Maybe something like this? Not sure if there's a more concise way of explaining it:

Suggested change
message: Pep508ErrorSource::String("Missing space before ';'".to_string()),
message: Pep508ErrorSource::String("\
Missing space before ';' creates an ambiguous requirement
(Unclear whether the ';' is part of the URL or separates the URL from an environment marker)".to_string()
),

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason itself is somewhat counterintuitive since we allow paths too, which unlike urls can contain spaces which we don't support except for the hack with file urls, and because PEP 508 doesn't require a semicolon after a version number for symmetry.

@konstin konstin enabled auto-merge (squash) February 20, 2024 16:34
@@ -976,12 +982,26 @@ fn parse(cursor: &mut Cursor, working_dir: Option<&Path>) -> Result<Requirement,
// wsp*
cursor.eat_whitespace();
if let Some((pos, char)) = cursor.next() {
if let Some(VersionOrUrl::Url(url)) = requirement_kind {
// Unwrap safety: The `VerbatimUrl` we just parsed has a string source.
if url.given().unwrap().ends_with(';') && marker.is_none() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we just make this if let rather than unwrap?

@konstin konstin merged commit a7513f4 into main Feb 20, 2024
7 checks passed
@konstin konstin deleted the konsti/missing-space-before-semicolon branch February 20, 2024 16:38
konstin added a commit that referenced this pull request Feb 20, 2024
konstin added a commit that referenced this pull request Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Messaging when something goes wrong
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to parse example @ example.whl; sys_platform == 'win32'
3 participants