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

Edit config files with a temp editor and add some validation #3945

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

leeavital
Copy link

Fixes #3905

This solves a problem where jj config edit drops you straight into an editor and allows you to save an invalid toml file. If you mess up your toml syntax, jj cannot launch (even jj config edit!)

This implements a pattern I've seen in tools like crontab -e or visudo where you get dropped into a temporary file editor and the tool does a bit of sanity checking before copying over the contents of the temporary file into the actual file.

Code wise: this reuses a utility function which takes care of the heavy lifting for creating a temporary file and launching an editor. I put all the validation in a new function in cli/src/config.rs, which seemed a bit like overkill but I figured the details of the config format being toml shouldn't leak into cli_util or command/config

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

Copy link

google-cla bot commented Jun 22, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Fixes martinvonz#3905

This solves a problem where `jj config edit` drops you straight into an editor and allows you to save an invalid toml file. If you mess up your toml syntax, jj cannot launch (even `jj config edit`!)

This implements a pattern I've seen in tools like `crontab -e` or `visudo` where you get dropped into a temporary file editor and the tool does a bit of sanity checking before copying over the contents of the temporary file into the actual file.

Code wise: this reuses a utility function which takes care of the heavy lifting for creating a temporary file and launching an editor.  I put all the validation in a new function in cli/src/config.rs, which seemed a bit like overkill but I figured the details of the config format being toml shouldn't leak into cli_util or command/config
@yuja
Copy link
Collaborator

yuja commented Jun 23, 2024

According to the issue comment, I think temporary backup + restore is preferred over editing temporary file.
#3905 (comment)

visudo has to be really strict (so the system will never get broken), but we wouldn't need a guarantee of that level.

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.

jj config edit doesn't reject invalid TOML
2 participants