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

Invalid values in boolean options in the environment cause traceback #5616

Closed
moshez opened this issue Jul 18, 2018 · 15 comments · Fixed by #5644
Closed

Invalid values in boolean options in the environment cause traceback #5616

moshez opened this issue Jul 18, 2018 · 15 comments · Fixed by #5644
Labels
auto-locked Outdated issues that have been locked by automation C: configuration Configuration management and loading good first issue A good item for first time contributors to work on type: bug A confirmed bug or unintended behavior

Comments

@moshez
Copy link

moshez commented Jul 18, 2018

Environment

  • pip version: 10.0.1
  • Python version: 3.6.6
  • OS: Debian Unstable

Description

When setting an environment variable that is supposed to hold a boolean value to an invalid string that is not empty, a traceback happens.

Expected behavior

An error message along the lines of "'blah' is not a valid value for ..., valid values

How to Reproduce

  1. pip install pip==10.0.1
  2. Run env PIP_REQUIRE_VIRTUALENV='blah' PYTHONPATH=src python -m pip install twisted
  3. Observe a traceback

Output

$ env PIP_REQUIRE_VIRTUALENV='blah' PYTHONPATH=src python -m pip install twisted                                                       
Traceback (most recent call last):                                             
  File "/home/moshez/.pyenv/versions/3.6.4/lib/python3.6/runpy.py", line 193, in
 _run_module_as_main                                                           
...
    values = self.get_default_values()
  File "/home/moshez/src/pip/src/pip/_internal/baseparser.py", line 230, in get_default_values
    defaults = self._update_defaults(self.defaults.copy())  # ours             
  File "/home/moshez/src/pip/src/pip/_internal/baseparser.py", line 195, in _update_defaults
    val = strtobool(val)
  File "/home/moshez/.pyenv/versions/3.6.4/lib/python3.6/distutils/util.py", line 317, in strtobool
    raise ValueError("invalid truth value %r" % (val,))                        
ValueError: invalid truth value 'blah'

Note

The documentation of strtobool (seen in the traceback above) says:

"True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0. Raises ValueError if val is anything else."

@pradyunsg pradyunsg added type: bug A confirmed bug or unintended behavior C: configuration Configuration management and loading labels Jul 18, 2018
@pradyunsg
Copy link
Member

Definitely a place where we can print a better error message. :)

@pradyunsg pradyunsg added this to the Print Better Error Messages milestone Jul 18, 2018
@pradyunsg pradyunsg added the good first issue A good item for first time contributors to work on label Jul 18, 2018
@pradyunsg
Copy link
Member

This issue is a good starting point for anyone who wants to help out with pip's development -- it's simple and the process of fixing this should be a good introduction to pip's development workflow. See the discussion above to understand what the desired fix is.

Feel free to mention me (write @pradyunsg in the comment) if you need help. :)

@sinscary
Copy link
Contributor

@pradyunsg can I take this up?

@pradyunsg
Copy link
Member

Sure. :)

@pradyunsg
Copy link
Member

@sinscary How's it going? Did you get some time to look into this?

@sinscary
Copy link
Contributor

@pradyunsg Sorry, actually I was kinda busy. Will try to finish it by today.

@sinscary
Copy link
Contributor

@pradyunsg what will be an appropriate error message in this case. What I can think of is -
"blah is not a valid value for require-virtualenv".

@pradyunsg
Copy link
Member

Yeah. And then have it use the default value that it would.

store_true's default is False, counts default is 0 and so on.

@sinscary
Copy link
Contributor

@pradyunsg So shouldn't it be exiting the process if ValueError occurs?
What I understood from your suggestion is, just print the error message and then assign default values to store_true, store_false and count and move on with the process.

@pradyunsg
Copy link
Member

Yeah... That's what I was suggesting.

Actually what you're suggesting also makes sense; pip should error out if the configuration provided to it is incorrect.

1 similar comment
@pradyunsg
Copy link
Member

Yeah... That's what I was suggesting.

Actually what you're suggesting also makes sense; pip should error out if the configuration provided to it is incorrect.

@sinscary
Copy link
Contributor

sinscary commented Jul 23, 2018

I think if pip doesn't error out, it might be confusing for many users(beginners mostly) as they won't be getting the desired behavior as per the configuration they have provided. So I think it will be better to exit the process with an error message rather than setting the default values. what say?

Anyways I am almost done and will raise a PR soon. 😄

@pfmoore
Copy link
Member

pfmoore commented Jul 23, 2018

I agree, I'd error out if the user gives an incorrect value.

@pradyunsg
Copy link
Member

Erroring out sounds good to me too. :)

sinscary added a commit to sinscary/pip that referenced this issue Jul 23, 2018
This catches code exception if wrong arguments passed to cmd options
It also adds error message that suggests correct arguments to pass

Fixes: pypa#5616
@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation C: configuration Configuration management and loading good first issue A good item for first time contributors to work on type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants