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

Improve error shown when there's no space between semicolon and url #592

Closed
wants to merge 3 commits into from
Closed

Improve error shown when there's no space between semicolon and url #592

wants to merge 3 commits into from

Conversation

Jackenmen
Copy link

Fixes #529

I kind of wanted to also show:

Expected space and semicolon (followed by markers) or end of string

when url doesn't end with ; but this sentence seemed a bit unnatural to me and I couldn't think of a better way of phrasing it + if the user ends up not putting a space, they'll get the better message when they try for the second time anyway.

I also originally wanted to say something more similar to Python's error messages, i.e. "Maybe you meant to put a space before the semicolon?" but that doesn't quite fit with the error message format ending with "at position ..":

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/work/packaging/packaging/requirements.py", line 42, in __init__
    raise InvalidRequirement(str(e))
packaging.requirements.InvalidRequirement: Expected semicolon (followed by markers) or end of string. Maybe you meant to put a space before the semicolon?
at position 59:
    tomli @ https://github.com/hukkin/tomli/archive/master.zip; python_version < '3.11'
                                                              ^

Either way, I'm open to suggestions.

@pradyunsg
Copy link
Member

We could add a “hint: maybe you meant…” line to the error message.

@Jackenmen
Copy link
Author

You mean like this?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/work/packaging/packaging/requirements.py", line 42, in __init__
    raise InvalidRequirement(str(e))
packaging.requirements.InvalidRequirement: Expected semicolon (followed by markers) or end of string. Hint: maybe you meant to put a space before the semicolon?
at position 59:
    tomli @ https://github.com/hukkin/tomli/archive/master.zip; python_version < '3.11'
                                                               ^

Instead of the currently proposed:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/work/packaging/packaging/requirements.py", line 42, in __init__
    raise InvalidRequirement(str(e))
packaging.requirements.InvalidRequirement: Expected space before semicolon (followed by markers) or end of string
at position 58:
    tomli @ https://github.com/hukkin/tomli/archive/master.zip; python_version < '3.11'
                                                              ^

@uranusjr
Copy link
Member

I think Pradyun means something like

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/work/packaging/packaging/requirements.py", line 42, in __init__
    raise InvalidRequirement(str(e))
packaging.requirements.InvalidRequirement: Expected space before semicolon (followed by markers) or end of string
at position 58:
    tomli @ https://github.com/hukkin/tomli/archive/master.zip; python_version < '3.11'

Maybe you mean this instead?
    tomli @ https://github.com/hukkin/tomli/archive/master.zip ; python_version < '3.11'

Had to update `raise_syntax_error()` to accept a suffix string
to put after the source string and error position marker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Present a clearer error message when the user misses a space before ; in marker
4 participants