Skip to content

fix(uninstall): don't crash on malformed settings.json (#434)#469

Open
isaukywhite wants to merge 1 commit into
DietrichGebert:mainfrom
isaukywhite:fix/uninstall-malformed-settings
Open

fix(uninstall): don't crash on malformed settings.json (#434)#469
isaukywhite wants to merge 1 commit into
DietrichGebert:mainfrom
isaukywhite:fix/uninstall-malformed-settings

Conversation

@isaukywhite

Copy link
Copy Markdown

What

Fixes a crash in scripts/uninstall.js when settings.json contains malformed JSON (#434).

Why

JSON.parse on a malformed settings.json throws a SyntaxError, which has no .code. The ENOENT-only catch re-threw it, crashing the script mid-cleanup — after .ponytail-active and config.json were already deleted (lines 21-22), leaving a non-zero exit and a dangling statusLine entry pointing at a soon-to-be-deleted script (which then errors on the next Claude Code launch).

How

Classify the error in the catch instead of checking only for ENOENT:

  • ENOENT → no settings.json, nothing to clean (swallow, unchanged)
  • SyntaxError → malformed JSON; can't safely edit it, so warn the user and leave the file intact
  • anything else → re-throw (unchanged; matches the re-throw-unexpected behavior of removeIfExists in the same file)

SyntaxError can only originate from JSON.parse here, so the classification is unambiguous.

Test

Added the missing malformed-JSON case to tests/uninstall.test.js: asserts exit 0, a warning is printed, and the file is left byte-for-byte intact. Closes the gap in the existing suite, which only covered valid and absent settings.json.

Note on the issue

The "settings.json may have been partially modified" concern doesn't actually occur: JSON.parse (line 27) throws before the synchronous writeFileSync (line 35), so the file is left untouched, never half-written. The real harm is the crash + the dangling statusLine reference — both addressed by this fix.

Closes #434

…t#434)

JSON.parse on a malformed settings.json throws a SyntaxError, which has no .code, so the ENOENT-only catch re-threw it — crashing the script mid-cleanup after .ponytail-active and config.json were already deleted. Classify the error instead: ENOENT swallows, SyntaxError warns and leaves the file intact, anything else still re-throws. Adds the missing malformed-JSON test case.

Co-Authored-By: Claude <noreply@anthropic.com>
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.

scripts/uninstall.js: malformed settings.json crashes script mid-cleanup, leaving state partially deleted

1 participant