Skip to content

fix: handle trailing commas in config JSON during installation and uninstallation - #3

Open
thaikolja wants to merge 1 commit into
anthonystepvoy:mainfrom
thaikolja:fix/json-trailing-comma-install
Open

fix: handle trailing commas in config JSON during installation and uninstallation#3
thaikolja wants to merge 1 commit into
anthonystepvoy:mainfrom
thaikolja:fix/json-trailing-comma-install

Conversation

@thaikolja

Copy link
Copy Markdown

Pull Request Description

Summary

Fixes a SyntaxError: Expected double-quoted property name in JSON error during installation/uninstallation when opencode.json contains trailing commas (a common issue in hand-edited JSON configuration files).

Root Cause

When executing install-opencode.sh or install-opencode.ps1 (as well as the corresponding uninstall scripts), the script attempts to parse ~/.config/opencode/opencode.json using standard JSON parsers (JSON.parse in Node.js, ConvertFrom-Json in PowerShell). If the JSON file contains trailing commas, standard parsers throw a syntax error and terminate script execution.

Changes

  • install-opencode.sh & uninstall-opencode.sh:
    • Wrapped JSON.parse in a try...catch block.
    • Added a fallback regex (content.replace(/,\s*([\]}])/g, "$1")) to strip trailing commas before parsing JSON in Node.js.
  • install-opencode.ps1 & uninstall-opencode.ps1:
    • Wrapped ConvertFrom-Json in a try...catch block.
    • Added a fallback regex ($content -replace ',\s*([\]}])', '$1') to strip trailing commas before parsing JSON in PowerShell.

Verification

  • Created an opencode.json configuration containing trailing commas (e.g., "caveman-compress": "allow",}).
  • Confirmed both Bash (install-opencode.sh) and PowerShell (install-opencode.ps1) scripts parse the file gracefully, apply configuration changes, and write back clean valid JSON.
  • Confirmed uninstall-opencode.sh and uninstall-opencode.ps1 successfully process files with trailing commas.

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.

1 participant