I need to handle configuration errors and ask the user for the right credentials if something is wrong. I cannot decide between three implementations. Which style is better in Python and why?
A:
while not backend.check_config():
click.echo('Invalid Configuration parameters!')
for param_name, question in backend.config.check_config_requires:
value = prompt(question, default=getattr(backend.config, param_name))
setattr(backend.config, param_name, value)
B:
while True:
try:
backend.validate_configcheck_config()
break
except ConfigurationError:
click.echo('Invalid Configuration parameters!')
for param_name, question in backend.config.check_config_requires:
value = prompt=prompt(question, default=getattr(backend.config, param_name))
setattr(backend.config, param_name, value)
C:
while True:
try:
backend.validate_configcheck_config()
except ConfigurationError:
click.echo('Invalid Configuration parameters!')
for param_name, question in backend.config.check_config_requires:
value = prompt=prompt(question, default=getattr(backend.config, param_name))
setattr(backend.config, param_name, value)
else:
break
check_config()
returns True
when everything is ok, validate_config()
raises exceptions on errors.