Skip to content

Commit

Permalink
Merge pull request #5644 from sinscary/fix_invalid_val_error
Browse files Browse the repository at this point in the history
Show appropriate error message
  • Loading branch information
pradyunsg authored Jul 27, 2018
2 parents d77e329 + ad78315 commit 7f4673d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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)

0 comments on commit 7f4673d

Please sign in to comment.