command/format: Don't panic when item removed from list of objects #20765
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.
Due to these tests happening in the wrong order, removing an object from the end of a sequence of objects would previously cause a bounds-check panic.
Rather than a more severe rework of the logic here, for now we'll just introduce an extra precondition to prevent the panic. The code that follows already handles the case where there is no new object (i.e. the "old" object is being deleted) as long as we're able to pass through this type-checking logic.
The new "JSON list of objects - removing item" test covers this problem by rendering a diff for an object being removed from the end of a list of objects within a JSON value.
This fixes #20750.