@@ -192,7 +192,14 @@ def _update_defaults(self, defaults):
192
192
continue
193
193
194
194
if option .action in ('store_true' , 'store_false' , 'count' ):
195
- val = strtobool (val )
195
+ try :
196
+ val = strtobool (val )
197
+ except ValueError :
198
+ error_msg = invalid_config_error_message (
199
+ option .action , key , val
200
+ )
201
+ self .error (error_msg )
202
+
196
203
elif option .action == 'append' :
197
204
val = val .split ()
198
205
val = [self .check_default (option , key , v ) for v in val ]
@@ -238,3 +245,16 @@ def get_default_values(self):
238
245
def error (self , msg ):
239
246
self .print_usage (sys .stderr )
240
247
self .exit (2 , "%s\n " % msg )
248
+
249
+
250
+ def invalid_config_error_message (action , key , val ):
251
+ """Returns a better error message when invalid configuration option
252
+ is provided."""
253
+ if action in ('store_true' , 'store_false' ):
254
+ return ("{0} is not a valid value for {1} option, "
255
+ "please specify a boolean value like yes/no, "
256
+ "true/false or 1/0 instead." ).format (val , key )
257
+
258
+ return ("{0} is not a valid value for {1} option, "
259
+ "please specify a numerical value like 1/0 "
260
+ "instead." ).format (val , key )
0 commit comments