Skip to content

fix(source): wrap only JSON parse errors in readJson - #4

Open
SebTardif wants to merge 1 commit into
openclaw:mainfrom
SebTardif:fix/readjson-syntaxerror-only
Open

SebTardif wants to merge 1 commit into
openclaw:mainfrom
SebTardif:fix/readjson-syntaxerror-only

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

What Problem This Solves

readJson caught every failure from readFileSync and JSON.parse and rethrew it as malformed JSON. A directory whose name ends in .json, a permission error, or a file that vanishes after existsSync all looked like a parse bug. Parse failures should stay labeled that way. I/O failures should keep their original code.

Evidence

Live node import of readJson on the patched tree. A path that is a directory throws EISDIR with no malformed JSON text. Truncated JSON still throws the wrapped parse message.

$ node --input-type=module -e "import { readJson } from './scripts/source.mjs'; ..."
DIR_NAME Error
DIR_CODE EISDIR
DIR_MSG EISDIR: illegal operation on a directory, read
PARSE_NAME Error
PARSE_MSG [clawsweeper-state] readJson: malformed JSON in C:\Users\sebta\AppData\Local\Temp\proof-json-pKZBgI\bad.json

Real behavior proof

  • Behavior or issue addressed: Directory and other I/O failures from readJson keep their original Node code. Only JSON.parse SyntaxError is wrapped as malformed JSON.
  • Real environment tested: Windows 11, Node v24.19.0, patched scripts/source.mjs on branch fix/readjson-syntaxerror-only.
  • Exact steps or command run after this patch: Created a temp path run.json as a directory and a sibling bad.json with truncated JSON. Imported readJson from ./scripts/source.mjs with node --input-type=module and called it on both paths.
  • Evidence after fix: terminal output from that node command (see Evidence). The directory path prints EISDIR and illegal operation on a directory. The truncated file prints the wrapped malformed JSON message.
  • Observed result after fix: The catch in readJson rethrows non-SyntaxError values unchanged, so operators see EISDIR instead of a fake parse failure.
  • What was not tested: EACCES on a locked file.

Change

scripts/source.mjs wraps SyntaxError only.

Origin

Introduced in 7964f2af5f7.

readJson labeled every thrown error as malformed JSON. Reading a
directory, hitting EACCES, or a disappearing file after existsSync
all produced that message. Keep the wrapper for SyntaxError only.

Signed-off-by: Sebastien Tardif <SebTardif@ncf.ca>
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