Error messages not clear enough
henningWoehr opened this issue · comments
Describe the problem
When using the flag --data-file
to input answers, there may be a validation error. Since normally, the error would be raised directly after answering, it is clear which questions was at fault. But with the data file, the error raised does not contain the question name or the choice in case of using choices. Therefore it is hard to find the wrong value in the data-file.
Template
preset:
type: str
help: Which config preset do you want to use?
choices:
- IIoT
- GPU
default: IIoT
config_mode:
type: str
help: Which config mode do you want to use?
choices:
Basic: basic
Advanced: advanced
default: basic
box_environment:
when: "{{config_mode == 'advanced'}}"
type: str
help: In which environment will the box run?
choices:
Production: prod
Development: dev
default: prod
validator: "{% if config_mode != 'advanced' %}Requires advanced config mode{% endif %}"
To Reproduce
When using the following values.yaml:
preset: IIoT
config_mode: basic
box_environment: dev
and the command copier copy <src> <dst> --data-file values.yaml
you would get the following error:
Traceback (most recent call last):
File "/home/henning/.local/bin/copier", line 8, in <module>
sys.exit(copier_app_run())
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/plumbum/cli/application.py", line 638, in run
inst, retcode = subapp.run(argv, exit=False)
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/plumbum/cli/application.py", line 633, in run
retcode = inst.main(*tailargs)
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/copier/cli.py", line 72, in handle_exceptions
return method(*args, **kwargs)
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/copier/cli.py", line 265, in main
with self._worker(
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/copier/main.py", line 205, in __exit__
raise value
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/copier/cli.py", line 272, in main
worker.run_copy()
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/copier/main.py", line 744, in run_copy
self._ask()
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/copier/main.py", line 443, in _ask
question.validate_answer(answer)
File "/home/henning/.local/pipx/venvs/copier-dist/lib/python3.10/site-packages/copier/user_data.py", line 411, in validate_answer
raise ValidationError(message=err_msg)
prompt_toolkit.validation.ValidationError: Requires advanced config mode
With this message, it isn't clear which question was answered wrong
Logs
No response
Expected behavior
Include nessessory names: question, choice or whatever is the most helpful.
What would be really nice, to validate similar to pydantic, where all validation errors are listed, but that would probably be too much, since it would only be useful when using --data-file
Screenshots/screencasts/logs
No response
Operating system
Linux
Operating system distribution and version
22.04
Copier version
9.1.0
Python version
3.10
Installation method
pipx+git
Additional context
No response
Hi, is there any update on this issue?
Hi @itz-salemm, as you can see, no, there is no update. Would you like to work on it 🙂?
Yes, I would get to work on it. I just wanted to confirm.
Thank you.