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

Show appropriate error message #5644

Merged
merged 4 commits into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/5644.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show a better error message when a configuration option has an invalid value.
22 changes: 21 additions & 1 deletion src/pip/_internal/baseparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@ def _update_defaults(self, defaults):
continue

if option.action in ('store_true', 'store_false', 'count'):
val = strtobool(val)
try:
val = strtobool(val)
except ValueError:
error_msg = invalid_config_error_message(
option.action, key, val
)
self.error(error_msg)

elif option.action == 'append':
val = val.split()
val = [self.check_default(option, key, v) for v in val]
Expand Down Expand Up @@ -238,3 +245,16 @@ def get_default_values(self):
def error(self, msg):
self.print_usage(sys.stderr)
self.exit(2, "%s\n" % msg)


def invalid_config_error_message(action, key, val):
"""Returns a better error message when invalid configuration option
is provided."""
if action in ('store_true', 'store_false'):
return ("{0} is not a valid value for {1} option, "
"please specify a boolean value like yes/no, "
"true/false or 1/0 instead.").format(val, key)

return ("{0} is not a valid value for {1} option, "
"please specify a numerical value like 1/0 "
"instead.").format(val, key)