-
Notifications
You must be signed in to change notification settings - Fork 614
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -931,12 +931,16 @@ fn parse(cursor: &mut Cursor, working_dir: Option<&Path>) -> Result<Requirement, | |||||||||||
|
||||||||||||
// ( url_req | name_req )? | ||||||||||||
let requirement_kind = match cursor.peek_char() { | ||||||||||||
// url_req | ||||||||||||
Some('@') => { | ||||||||||||
cursor.next(); | ||||||||||||
Some(VersionOrUrl::Url(parse_url(cursor, working_dir)?)) | ||||||||||||
} | ||||||||||||
// name_req | ||||||||||||
Some('(') => parse_version_specifier_parentheses(cursor)?, | ||||||||||||
// name_req | ||||||||||||
Some('<' | '=' | '>' | '~' | '!') => parse_version_specifier(cursor)?, | ||||||||||||
// No requirements / any version | ||||||||||||
Some(';') | None => None, | ||||||||||||
Some(other) => { | ||||||||||||
// Rewind to the start of the version specifier, to see if the user added a URL without | ||||||||||||
|
@@ -963,6 +967,8 @@ fn parse(cursor: &mut Cursor, working_dir: Option<&Path>) -> Result<Requirement, | |||||||||||
} | ||||||||||||
}; | ||||||||||||
|
||||||||||||
let requirement_end = cursor.pos; | ||||||||||||
|
||||||||||||
// wsp* | ||||||||||||
cursor.eat_whitespace(); | ||||||||||||
// quoted_marker? | ||||||||||||
|
@@ -976,12 +982,24 @@ 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() { | ||||||||||||
return Err(Pep508Error { | ||||||||||||
message: Pep508ErrorSource::String("Missing space before ';'".to_string()), | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||
start: requirement_end - ';'.len_utf8(), | ||||||||||||
len: ';'.len_utf8(), | ||||||||||||
input: cursor.to_string(), | ||||||||||||
}); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
let message = if marker.is_none() { | ||||||||||||
format!(r#"Expected end of input or ';', found '{char}'"#) | ||||||||||||
} else { | ||||||||||||
format!(r#"Expected end of input, found '{char}'"#) | ||||||||||||
}; | ||||||||||||
return Err(Pep508Error { | ||||||||||||
message: Pep508ErrorSource::String(if marker.is_none() { | ||||||||||||
format!(r#"Expected end of input or ';', found '{char}'"#) | ||||||||||||
} else { | ||||||||||||
format!(r#"Expected end of input, found '{char}'"#) | ||||||||||||
}), | ||||||||||||
message: Pep508ErrorSource::String(message), | ||||||||||||
start: pos, | ||||||||||||
len: char.len_utf8(), | ||||||||||||
input: cursor.to_string(), | ||||||||||||
|
@@ -1470,9 +1488,9 @@ mod tests { | |||||||||||
assert_err( | ||||||||||||
r#"name @ https://example.com/; extra == 'example'"#, | ||||||||||||
indoc! {" | ||||||||||||
Expected end of input or ';', found 'e' | ||||||||||||
Missing space before ';' | ||||||||||||
name @ https://example.com/; extra == 'example' | ||||||||||||
^" | ||||||||||||
^" | ||||||||||||
}, | ||||||||||||
); | ||||||||||||
} | ||||||||||||
|
There was a problem hiding this comment.
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 thanunwrap
?