Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: let 'set' command fail on key not found #33

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

limaa
Copy link
Contributor

@limaa limaa commented Jun 21, 2024

Whenever a key is not found within a 'set' command. The command should error out instead of trying to continue execution and assign the value to a partially parsed key.

Example:
toml set --toml-path pyproject.toml tool.ruffs.target-version py39

The table tool.ruffs does not exist but the current implementation captures this exception and continues along, actually executing tool.target-version = "py39".

I believe a better implementation is to not capture the exception at all and error out, this way no unintended modifications to the TOML file are performed.

Another option is to continue capturing the exception but error out using exit(1).

What do you think?

@mrijken
Copy link
Owner

mrijken commented Jun 22, 2024

Thanx, I do prefer the exit(1) variant, because the user don't need the Python traceback.

Whenever a key is not found within a 'set' command, the command should
error out instead of trying to continue execution and assign the value
to a partially parsed key. This way no unintended modifications to the
TOML file are performed.

Example:
`toml set --toml-path pyproject.toml tool.ruffs.target-version py39`

The table `tool.ruffs` does not exist but the current implementation
captures this exception and continues along, actually executing
`tool.target-version = "py39"`.
@limaa
Copy link
Contributor Author

limaa commented Jun 24, 2024

I have updated to use exit(1) and added more information on the error message, now it prints:

error: non-existent key 'tool.ruffs.target-version' can not be set to value 'py39'

@mrijken mrijken merged commit f21f48b into mrijken:master Jun 24, 2024
1 check passed
@limaa limaa deleted the fix/set-key-failure branch June 27, 2024 18:38
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.

2 participants