Skip to content

fix(config): report the setting name for invalid integer values - #11149

Open
XXXXXQ-0206 wants to merge 1 commit into
python-poetry:mainfrom
XXXXXQ-0206:fix/config-invalid-int-message
Open

XXXXXQ-0206 wants to merge 1 commit into
python-poetry:mainfrom
XXXXXQ-0206:fix/config-invalid-int-message

Conversation

@XXXXXQ-0206

Copy link
Copy Markdown

What does this PR do?

Invalid values for the three integer settings now report the same uniform error as every other setting, instead of the raw int() conversion error.

Why

ConfigCommand._handle_single_value() produces "{value}" is an invalid value for {key} for validators that return False; that message is pinned by tests/console/commands/test_config.py::test_cannot_set_invalid_value. The validators for requests.max-retries, installer.max-workers and solver.min-release-age are lambdas calling int(), so they raise ValueError and bypass that message - the user saw invalid literal for int() with base 10: 'abc' without knowing which setting failed.

This change treats a raising validator as an invalid value, keeping the pinned message unchanged:

try:
    valid = validator(value)
except ValueError:
    valid = False

The environment-variable path gets the same treatment in Config.get(): POETRY_REQUESTS_MAX_RETRIES=abc now raises PoetryError: Invalid value for POETRY_REQUESTS_MAX_RETRIES: 'abc' instead of the unrelated ValueError message.

Tests

  • test_cannot_set_invalid_integer_value (three parametrized settings) and test_invalid_integer_from_environment both fail on main with ValueError and pass with this change.

Related

No duplicate open or closed PR covers this path: exact-error-text searches return nothing. Other open PRs touch the same files in different regions (#11057 in console/commands/config.py near line 140; #11115, #11116 and #11120 in config.py near lines 334-342, 248 and 427), so merge order should not conflict.

Resolves #11148

Copilot AI balanced review requested due to automatic review settings October 17, 2026 18:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/poetry/console/commands/config.py" line_range="389" />
<code_context>
+            # Some validators (e.g. those that parse integers) raise instead
+            # of returning False; surface them like any other invalid value.
+            valid = False
+        if not valid:
             raise RuntimeError(f'"{value}" is an invalid value for {key}')

</code_context>
<issue_to_address>
**Invalid integers inject terminal controls**

When a CI caller passes an invalid integer containing terminal escape sequences to `poetry config`, `_handle_single_value` now treats the validator’s `ValueError` as invalid input and reaches the direct `f"{value}"` error at `config.py:390`; the CLI emits embedded terminal control characters, allowing the supplied value to manipulate terminal output.

Escape terminal control characters in the displayed value before constructing the error message.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/poetry/console/commands/config.py:389


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

# Some validators (e.g. those that parse integers) raise instead
# of returning False; surface them like any other invalid value.
valid = False
if not valid:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Invalid integers inject terminal controls

When a CI caller passes an invalid integer containing terminal escape sequences to poetry config, _handle_single_value now treats the validator’s ValueError as invalid input and reaches the direct f"{value}" error at config.py:390; the CLI emits embedded terminal control characters, allowing the supplied value to manipulate terminal output.

Escape terminal control characters in the displayed value before constructing the error message.

Prompt for AI agents
In `src/poetry/console/commands/config.py` at line 389:

**Invalid integers inject terminal controls**

When a CI caller passes an invalid integer containing terminal escape sequences to `poetry config`, `_handle_single_value` now treats the validator’s `ValueError` as invalid input and reaches the direct `f"{value}"` error at `config.py:390`; the CLI emits embedded terminal control characters, allowing the supplied value to manipulate terminal output.

Escape terminal control characters in the displayed value before constructing the error message.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: report the setting name for invalid integer values

2 participants