Skip to content

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

Merged
DietrichGebert merged 1 commit into
mainfrom
fix/434-malformed-settings
Jul 1, 2026
Merged

fix: don't crash uninstall on malformed settings.json (#434)#481
DietrichGebert merged 1 commit into
mainfrom
fix/434-malformed-settings

Conversation

@DietrichGebert

Copy link
Copy Markdown
Owner

Problem

Closes #434. In scripts/uninstall.js, a malformed settings.json makes JSON.parse throw a SyntaxError, which has no .code, so if (e.code !== 'ENOENT') throw e rethrew it and crashed the script — after the mode flag and config file were already removed, leaving cleanup half-done.

Reproduced on current main: with a malformed settings.json the script exits non-zero with an uncaught SyntaxError, after .ponytail-active was already deleted.

Fix

Handle SyntaxError explicitly in the catch: warn that the statusLine entry couldn't be removed and leave the file untouched (invalid JSON can't be safely edited), then exit 0. ENOENT stays a no-op; any other error still rethrows.

Verification

  • npm test: 70 + 15 pass, exit 0. check-rule-copies / check-versions: exit 0.
  • Added a regression test: malformed settings.json → exit 0, warns, file left byte-for-byte intact.
  • e2e: with a stale flag present and malformed settings.json, the flag is removed, the script warns and exits 0, and settings.json is unchanged.

Note

Supersedes #469 (same fix by @isaukywhite, credited as co-author), which branched before #479 (combined-statusline guard) and #480 landed and so conflicts on both changed files. This reconciles the identical fix onto current main. Suggest closing #469 in favor of this. (#471 is a separate packaging concern, not touched here.)

If settings.json contained invalid JSON, JSON.parse threw a SyntaxError, which
has no .code, so the catch rethrew it and crashed the script — after the mode
flag and config file were already removed, leaving cleanup half-done. Handle
SyntaxError explicitly: warn that the statusLine entry couldn't be removed and
leave the file untouched, since invalid JSON can't be safely edited. Adds a
regression test that a malformed settings.json exits 0, warns, and is left
byte-for-byte intact.

Closes #434

Co-authored-by: isaukywhite <50426537+isaukywhite@users.noreply.github.com>
@DietrichGebert DietrichGebert merged commit 40e50d9 into main Jul 1, 2026
1 check passed
@DietrichGebert DietrichGebert deleted the fix/434-malformed-settings branch July 1, 2026 23:30
github-actions Bot pushed a commit to harshav167/ponytail that referenced this pull request Jul 2, 2026
…#481)

If settings.json contained invalid JSON, JSON.parse threw a SyntaxError, which
has no .code, so the catch rethrew it and crashed the script — after the mode
flag and config file were already removed, leaving cleanup half-done. Handle
SyntaxError explicitly: warn that the statusLine entry couldn't be removed and
leave the file untouched, since invalid JSON can't be safely edited. Adds a
regression test that a malformed settings.json exits 0, warns, and is left
byte-for-byte intact.

Closes DietrichGebert#434

Co-authored-by: isaukywhite <50426537+isaukywhite@users.noreply.github.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