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

Rollback context if edit invalid #682

Merged
merged 4 commits into from
Jan 26, 2023
Merged

Rollback context if edit invalid #682

merged 4 commits into from
Jan 26, 2023

Conversation

sethjback
Copy link
Contributor

Since the cli launches an external editor validation of the updated context cannot be done until after it has already been saved to disk. The result is when you enter bad data (e.g. invalid nsc path) it will get persisted before the cli notifies you of the error. If you then try to run the edit command again it will fail due to validation checks failing when attempting to load the now bad context. The only solution is to manually edit the context .json file on disk.

This PR will check for errors when loading the context after the editor command has returned. If the context fails to validate it will attempt to save the known clean context so that the nats edit context command will run in the future. It then returns the error to let the user know what part of the updated context failed validation.

This is not a perfect solution: if you have made multiple changes to the context config they all get reverted instead of just the invalid ones. However, this will at least solve the frustrating situation of making a mistake in the context edit and then getting "locked out" of editing it again.

cli/context_command.go Outdated Show resolved Hide resolved
cli/context_command.go Outdated Show resolved Hide resolved
@sethjback sethjback merged commit 3675915 into main Jan 26, 2023
@sethjback sethjback deleted the nsc-edit-context branch January 26, 2023 16:11
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