Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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. invalidnsc
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.