Improve error message for invalid virtualenvs.prompt config#10649
Improve error message for invalid virtualenvs.prompt config#10649aryanyk wants to merge 3 commits intopython-poetry:mainfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideImproves handling of invalid template variables in the virtualenv prompt configuration by converting a raw KeyError into a clearer, user-facing PoetryError with guidance on how to fix the configuration. Sequence diagram for handling invalid virtualenvs.prompt template variablessequenceDiagram
actor User
participant PoetryCLI
participant EnvManager
participant PythonFormatEngine
User->>PoetryCLI: Run_command_that_creates_virtualenv
PoetryCLI->>EnvManager: create_venv(venv_prompt)
alt venv_prompt_is_not_none
EnvManager->>PythonFormatEngine: venv_prompt.format(project_name, python_version)
alt template_variable_is_valid
PythonFormatEngine-->>EnvManager: formatted_prompt
EnvManager-->>PoetryCLI: virtualenv_created_with_custom_prompt
PoetryCLI-->>User: Command_succeeds
else template_variable_is_invalid
PythonFormatEngine-->>EnvManager: KeyError
EnvManager-->>PoetryCLI: PoetryError_invalid_template_variable
PoetryCLI-->>User: Clear_error_message_with_config_guidance
end
else venv_prompt_is_none
EnvManager-->>PoetryCLI: virtualenv_created_with_default_prompt
PoetryCLI-->>User: Command_succeeds
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Consider including the list of supported template variables (e.g.
project_name,python_version) in the error message so users immediately know what they can use instead of the invalid placeholder. - If possible, reference the concrete config file path or source (e.g.
poetry config --listor the actual file location) in the error message rather than the generic 'Poetry configuration file' to make it easier for users to locate and fix the setting.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider including the list of supported template variables (e.g. `project_name`, `python_version`) in the error message so users immediately know what they can use instead of the invalid placeholder.
- If possible, reference the concrete config file path or source (e.g. `poetry config --list` or the actual file location) in the error message rather than the generic 'Poetry configuration file' to make it easier for users to locate and fix the setting.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Thanks for the feedback! Makes sense — I’ll update the error message to include the supported template variables and reference the concrete config source so it’s easier for users to fix. Will push an update shortly. |
|
I’ve updated the error message to include the supported template variables and more concrete config hints, and applied Ruff formatting. Let me know if you’d like the wording tweaked further. |
|
Hi @radoering , I’ve pushed the requested changes and all CI checks are green now ✅ Thanks for your time and guidance! |
radoering
left a comment
There was a problem hiding this comment.
Unfortunately, someone else created a similar PR shortly before you: #10648.
Since that PR covers an additional error, adds tests and was the first one, I tend to prefer it - if the author addresses the review feedback.
Thank you anyway.
| except KeyError as e: | ||
| raise PoetryError( | ||
| f'Invalid template variable "{e.args[0]}" in ' | ||
| 'global configuration option "virtualenvs.prompt".\n\n' |
There was a problem hiding this comment.
It is not necessarily in the global configuration. It can also be in the local configuration.
| 'global configuration option "virtualenvs.prompt".\n\n' | ||
| "Supported variables are: project_name, python_version.\n" | ||
| "You can update this setting via:\n" | ||
| " - ~/.config/pypoetry/config.toml\n" |
There was a problem hiding this comment.
That is only the path for Linux and only the global configuration. It probably makes more sense to recommend setting it via poetry config [--local] virtualenvs.prompt <value>.
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Pull Request Check List
Resolves: #Resolves: #10635
Summary
Improve error message when an invalid template variable is used in
virtualenvs.promptconfiguration.Details
Previously an invalid placeholder such as
{python-version}resulted ina cryptic KeyError. This change catches the error and raises a clearer
PoetryError explaining the config source and how to fix it.
Testing
Summary by Sourcery
Bug Fixes: