Error message for incorrect configs is unclear
Issue Kind
Change in current behaviour
Description
The messages for errors in the global configuration could be somewhat clearer (and reported immediately as such).
What I did
I changed the prompt in my ~/.config/pypoetry/config.toml to a malformed value
[virtualenvs]
prompt = "{project_name} [{python-version}]"
(sic, it should say python_version but I did not notice that).
What I got
Any operation resulting in dealing with a new venv (poetry init, poetry install, poetry env use python3.13...) would suddenly fail, with nothing but an empty line and a message
"python-version"
in red letters. Deleting and reinstalling poetry via curl, with pipx or any other way did not help. However, other active venvs continued working fine. After finally finding the root cause and changing to python_version, everything works again and the prompt is indeed changed according to my preference.
What I would expect
A clearer message stating the origin of the problem in the config file (like Undefined template variable "python-version" in "virtualenvs.prompt" read from "~/.config/pypoetry/config.toml") , or at least something saying that the error comes from the global configuration, and not from Python or local pyproject.toml. Ideally this should come as soon as possible after the wrong config is saved.
What made it particularly bad was that the time between me changing it and the first symptoms was fairly long. I did not create any new venvs inbetween, and old ones continued working without problems even with an incorrect config. Only when I recreated them during unrelated troubleshooting the problem surfaced. I suppose that it does not affect venvs that already existed at the time the wrong config was introduced, only new ones.
Impact
I spent over two hours trying to find a trivial configuration error, and a long time after I introduced it. No amount of searching or consulting with a LLM would help as there was no error message.
Workarounds
Probably no workarounds, just pay very close attention to what you are doing.
You forgot to provide the information that the issue template asks for, especially the output of poetry -vvv <command>
If you did that then the stack trace would make the error much more guessable, and also suggest the right place to make a not-too-hard fix - pull requests welcome I'm sure.
KeyError
'python-version'
at ~/.local/share/pipx/venvs/poetry/lib/python3.12/site-packages/poetry/utils/env/env_manager.py:446 in create_venv
442│ name = f"{name}-py{python.minor_version.to_string()}"
443│ venv = venv_path / name
444│
445│ if venv_prompt is not None:
→ 446│ venv_prompt = venv_prompt.format(
447│ project_name=self._poetry.package.name or "virtualenv",
448│ python_version=python.minor_version.to_string(),
449│ )
450│
Ah, terribly sorry, I did not notice that. The "feature request" template does not ask for poetry -vvv output (I see now that the "bug report" one does, but I found this more fitting, as strictly speaking it is not a bug).
I agree, in that case the cause and the solution are obvious.
Hi @sesquideus 👋
This looks like a great DX improvement. I’d like to work on improving the error message and early detection for invalid config keys like python-version in virtualenvs.prompt.
I’ll investigate and open a PR if I can implement a clean fix. Let me know if that sounds good.
Hi @aryanyk
I was planning to open a PR myself but I am quite busy these days. If you can do it now, by all means, go for it 👍🏻
Hi @sesquideus
I recently pushed the PR with required changes and now it gives result as expected . Also I have added the proper error message as you want and will help developers to navigate easily. I hope you like it . If you want any changes, feel free to reach out to me.