Skip to content

Commit

Permalink
show error message with wrong configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
sinscary committed Jul 24, 2018
1 parent 01a0fa5 commit e5dc3cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion news/5644.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Show appropriate error message if invalid args passed
Show a better error message when a configuration option has an invalid value.
19 changes: 14 additions & 5 deletions src/pip/_internal/baseparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,8 @@ def _update_defaults(self, defaults):
val = strtobool(val)
except ValueError:
self.error(
"#{0} is not a valid value. Valid true values"
"are {1}, {2}, {3}, {4} and valid false values"
"are {5}, {6}, {7}, {8}".format(
val, "true", "yes", "on", 1,
"false", "no", "off", 0
self.invalid_config_error_message(
option.action, key, val
)
)
elif option.action == 'append':
Expand Down Expand Up @@ -245,6 +242,18 @@ def get_default_values(self):
defaults[option.dest] = option.check_value(opt_str, default)
return optparse.Values(defaults)

def invalid_config_error_message(self, 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)

def error(self, msg):
self.print_usage(sys.stderr)
self.exit(2, "%s\n" % msg)

0 comments on commit e5dc3cf

Please sign in to comment.