Skip to content

Commit e5dc3cf

Browse files
committed
show error message with wrong configuration option
1 parent 01a0fa5 commit e5dc3cf

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

news/5644.bugfix

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Show appropriate error message if invalid args passed
1+
Show a better error message when a configuration option has an invalid value.

src/pip/_internal/baseparser.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,8 @@ def _update_defaults(self, defaults):
196196
val = strtobool(val)
197197
except ValueError:
198198
self.error(
199-
"#{0} is not a valid value. Valid true values"
200-
"are {1}, {2}, {3}, {4} and valid false values"
201-
"are {5}, {6}, {7}, {8}".format(
202-
val, "true", "yes", "on", 1,
203-
"false", "no", "off", 0
199+
self.invalid_config_error_message(
200+
option.action, key, val
204201
)
205202
)
206203
elif option.action == 'append':
@@ -245,6 +242,18 @@ def get_default_values(self):
245242
defaults[option.dest] = option.check_value(opt_str, default)
246243
return optparse.Values(defaults)
247244

245+
def invalid_config_error_message(self, action, key, val):
246+
"""Returns a better error message when invalid configuration option
247+
is provided."""
248+
if action in ('store_true', 'store_false'):
249+
return ("{0} is not a valid value for {1} option, "
250+
"please specify a boolean value like yes/no, "
251+
"true/false or 1/0 instead.").format(val, key)
252+
253+
return ("{0} is not a valid value for {1} option, "
254+
"please specify a numerical value like 1/0 "
255+
"instead.").format(val, key)
256+
248257
def error(self, msg):
249258
self.print_usage(sys.stderr)
250259
self.exit(2, "%s\n" % msg)

0 commit comments

Comments
 (0)