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

Present a clearer error message when the user misses a space before ; in marker #529

Closed
pradyunsg opened this issue Apr 2, 2022 · 5 comments · Fixed by #624
Closed

Present a clearer error message when the user misses a space before ; in marker #529

pradyunsg opened this issue Apr 2, 2022 · 5 comments · Fixed by #624

Comments

@pradyunsg
Copy link
Member

pradyunsg commented Apr 2, 2022

Currently, if you try to use:

tomli @ https://github.com/hukkin/tomli/archive/master.zip; python_version < '3.11'

The error you get is:

>>> Requirement("tomli @ https://github.com/hukkin/tomli/archive/master.zip; python_version < '3.11'")
Traceback (most recent call last):
  File "/Users/pradyunsg/Developer/github/packaging/.venv/lib/python3.11/site-packages/packaging/requirements.py", line 102, in __init__
    req = REQUIREMENT.parseString(requirement_string)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pradyunsg/Developer/github/packaging/.venv/lib/python3.11/site-packages/pyparsing/core.py", line 1141, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected string_end, found 'python'  (at char 60), (line:1, col:61)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/pradyunsg/Developer/github/packaging/.venv/lib/python3.11/site-packages/packaging/requirements.py", line 104, in __init__
    raise InvalidRequirement(
packaging.requirements.InvalidRequirement: Parse error at "'python_v'": Expected string_end

It would be good if it presented an error that suggested adding a (space) before the semicolon.

@Jackenmen
Copy link

I think this was supposed to refer to packaging.requirements as:

tomli @ https://github.com/hukkin/tomli/archive/master.zip ; python_version < '3.11'

is not a valid marker string.
Assuming that's true, I made #592 to fix the issue.

@pradyunsg
Copy link
Member Author

pradyunsg commented Dec 7, 2022

In #624, these cases get an error like:

packaging.requirements.InvalidRequirement: Expected end or semicolon (after URL and whitespace)
    package @ https://example.com/; python_version <= '3.2'
              ~~~~~~~~~~~~~~~~~~~~~~^

@Jackenmen
Copy link

Could the arrow's position be adjusted so that it points at the semicolon's position (since that's where the space is missing)? I think that it pointing at the first letter of the marker is confusing.

// #592 also hints directly that it might be the space between URL and semicolon that's missing while in your error it IMO seems a bit less clear. But I guess users will probably be able to figure it out just fine anyway so I wouldn't say it's a big deal.

@pradyunsg
Copy link
Member Author

pradyunsg commented Dec 7, 2022

Yea, I flip-flopped on those aspects (I think that might actually be visible in the force-push history), and ended up on this style since it was consistent with how "bad" versions specifiers ended up being handled:

packaging.requirements.InvalidRequirement: Expected end or semicolon (after version specifier)
     name ==0.this.is.a.bad.version ; python_version == "1.0"
          ~~~^

@pradyunsg
Copy link
Member Author

pradyunsg commented Dec 7, 2022

Granted all of the options we have at hand are improvements over the current variant. :)

packaging.requirements.InvalidRequirement: Parse error at "'python_v'": Expected string_end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants