Hint at missing quote in marker (#6414)

For https://github.com/astral-sh/uv/issues/6379#issuecomment-2303074836.

Input: `name; python_version == 3.10`
Error:
```
Expected a quoted string or a valid marker name, found '3.10'
name; python_version == 3.10
                        ^^^^
```
This commit is contained in:
konsti 2024-08-22 10:15:47 +02:00 committed by GitHub
parent 681d605bd9
commit c2088af78d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 5 deletions

View file

@ -1645,9 +1645,10 @@ mod tests {
assert_snapshot!(
parse_pep508_err(r"name; invalid_name"),
@"
Expected a valid marker name, found 'invalid_name'
Expected a quoted string or a valid marker name, found 'invalid_name'
name; invalid_name
^^^^^^^^^^^^"
^^^^^^^^^^^^
"
);
}
@ -1656,9 +1657,10 @@ mod tests {
assert_snapshot!(
parse_pep508_err("name; '3.7' <= invalid_name"),
@"
Expected a valid marker name, found 'invalid_name'
Expected a quoted string or a valid marker name, found 'invalid_name'
name; '3.7' <= invalid_name
^^^^^^^^^^^^"
^^^^^^^^^^^^
"
);
}
@ -1673,6 +1675,18 @@ mod tests {
);
}
#[test]
fn error_missing_quote() {
assert_snapshot!(
parse_pep508_err("name; python_version == 3.10"),
@"
Expected a quoted string or a valid marker name, found '3.10'
name; python_version == 3.10
^^^^
"
);
}
#[test]
fn error_markers_inpython_version() {
assert_snapshot!(

View file

@ -103,7 +103,7 @@ pub(crate) fn parse_marker_value<T: Pep508Url>(
let key = cursor.slice(start, len);
MarkerValue::from_str(key).map_err(|_| Pep508Error {
message: Pep508ErrorSource::String(format!(
"Expected a valid marker name, found '{key}'"
"Expected a quoted string or a valid marker name, found '{key}'"
)),
start,
len,