Repository navigation
Don't throw when removing a property whose parent doesn't exist - #153
Draft
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
Draft
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
Conversation
`modify(text, path, undefined)` threw "Can not delete in empty document"
whenever an object or array on the path was missing, for example when
removing `['[typescript]', 'editor.formatOnSave']` from `{"a": 1}`. The
property doesn't exist, so there is nothing to remove: return no edits, as
is already done when only the last segment is missing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Federico Brancasi (federicobrancasi)
requested a balanced review from Copilot
November 29, 2026 00:27
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change making deletion a no-op when its parent is absent.
No open issues 🎉
What changed in this PR
Makes property deletion through modify a no-op when the parent does not exist, avoiding an exception when editing JSON settings.
Changes:
- Returns an empty edit list instead of throwing when deletion finds no parent.
- Adds regression coverage for a missing parent property and an empty document.
| File | Description |
|---|---|
src/test/edit.test.ts |
Tests deletion with a missing parent and an empty document. |
src/impl/edit.ts |
Returns no edits when deletion finds no parent. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Removing a property whose parent object doesn't exist throws "Can not delete in empty document", for example
modify('{"a":1}', ['[typescript]', 'editor.formatOnSave'], undefined, options). The document isn't empty, and there is nothing to delete.setPropertywalks up the path to the closest parent that exists, and when there is none it threw for a deletion.This PR returns no edits instead, as it already does when only the last segment is missing, and as VS Code's copy of this code does since microsoft/vscode#210025. Tools that edit settings files with
modifyhit this error, for example Kilo-Org/kilocode#12453.How to test
npx tsc -p ./src && npm run lint && node --enable-source-maps --test ./lib/esm/test/*.test.js