Skip to content

fix(settings): name the file when settings.json does not parse - #1349

Merged
agegr merged 1 commit into
agegr:mainfrom
brynne8:fix/settings-error-names-the-file
Oct 29, 2026
Merged

agegr merged 1 commit into
agegr:mainfrom
brynne8:fix/settings-error-names-the-file

Conversation

@brynne8

@brynne8 brynne8 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

What it does

A global settings.json that does not parse is now reported with the path of the file in front of the parser's message:

/Users/me/.pi/agent/settings.json: Expected property name or '}' in JSON at position 2 (line 1 column 3)

(The parser's own text is Node's, and its wording differs between Node versions; the path in front of it does not.)

The refusal is unchanged — the file is still left exactly where it is, its bytes untouched, and every write against it is still refused until the user repairs it by hand. Only the text of the diagnostic changes, and it now follows the <path>: <parse error> form the Plugins route already uses for pi's settings errors.

Every caller built on the module surfaces the message unchanged: /api/tools/settings and /api/cache-miss-notices in their 500 body, the MCP listing as preferenceError, modeError and inlineBudgetError.

Why it matters

On main the diagnostic is the parser's text alone, with no path in it. Settings › General's switch and Settings › MCP's Code mode, PowerShell and tool-list-budget switches show that text and nothing else, so the user is told that a file is broken but not which one — and settings.json is the file pi itself writes, so it is the one most likely to be edited by hand.

This is the part of the earlier attempt that fits upstream. In the closing comment on #1327, the maintainer wrote:

Your point about the message is fair: today it's only the parser's text, without the file. A small PR that keeps refusing but puts the path in the error (<path>: <parse error>, the way the Plugins route already shows pi's settings errors) would be welcome.

This is that PR: the refusal stays, and the path goes into the error.

Reproduction

On main:

printf '{ not json' > ~/.pi/agent/settings.json
curl -s localhost:30141/api/tools/settings     # 500, "Expected property name or '}' in JSON at position 2 …"
curl -s localhost:30141/api/cache-miss-notices # 500, same message
curl -s localhost:30141/api/mcp | jq .codemode # mode and inlineBudget unset, each with that message
ls ~/.pi/agent/                                # settings.json only, unchanged

The message never says which file is broken.

On this branch the same three requests answer with the same refusals and the same text, prefixed by the path:

curl -s localhost:30141/api/tools/settings
# 500, "/Users/me/.pi/agent/settings.json: Expected property name or '}' in JSON at position 2 …"
ls ~/.pi/agent/
# settings.json only, still the same bytes

Scope

One change: the path is added to the parse error. The file is not moved, renamed, backed up or repaired; the refusal stays a refusal; the error stays a SyntaxError; a settings file that parses to something other than an object keeps its own message.

lib/global-settings-file.ts is the whole implementation, plus lib/global-settings-file.test.mjs, which is new and pins the reported path, the file left in place with its bytes kept, the refused write, and a valid file read and written as before. Nothing else in the tree changes: the readers and writers already surface the message they are thrown, and no user-visible string is added — the text is the English server diagnostic the panels already show for an internal failure.

Deliberately not done: no recovery path. Pi Web does not move, rename, back up or rewrite the file, does not offer to repair it, and does not start writing to it again. settings.json is pi's file as much as Pi Web's — pi's SettingsManager reads and writes it, and pi's own contract on an unparsable file is to report the error, leave the file in place and skip every write until the user fixes it. Pi Web keeps that contract, and only makes the message actionable by naming the file the user has to repair.

Testing

lib/global-settings-file.test.mjs is new and covers the four cases directly. The existing assertions in lib/codemode-settings.test.mjs, app/api/tools/settings/route.test.mjs and app/api/mcp/route.test.mjs — SyntaxError out of the writers, the corrupt bytes still at settingsPath, refusal.error matching /JSON/ — still hold and were not changed.

export PATH="$HOME/.nvm/versions/node/v26.7.0/bin:$PATH"
node --version   # v26.7.0

node --experimental-strip-types --test \
  lib/global-settings-file.test.mjs lib/codemode-settings.test.mjs \
  app/api/tools/settings/route.test.mjs app/api/mcp/route.test.mjs
# 38 tests, 38 pass, 0 fail

npm test          # 2803 tests, 2802 pass, 1 skipped, 0 fail
npx tsc --noEmit  # clean
npx eslint .      # clean

Provenance

Split out of a Bun-running fork (brynne8/pi-web-bun) into a single-purpose branch on today's main; one feature per PR.

The behaviour was written for this branch rather than taken from the earlier attempt: the earlier one moved the file aside, which upstream declined for the reasons quoted above. Here the file stays, and only the message changes.

A global `settings.json` that does not parse is reported with the
parser's own text alone, so the diagnostic does not say which file is
broken. The message now names the path, in the `<path>: <parse error>`
form the Plugins route already uses for pi's settings errors.

The file is not moved, renamed or repaired. `settings.json` belongs to
pi's `SettingsManager`, which reads and writes the same file: when pi
cannot parse it, pi reports the error, leaves the file where it is and
skips every write until the user repairs it by hand. Pi Web keeps
refusing too, and now says which file the user has to repair. Moving
the file aside would let the next write create a fresh `settings.json`
holding one key, which pi would read as a valid file with no
`defaultModel`, no `enabledModels` and no `packages` — and report no
error at all.

The error stays a `SyntaxError`, the refusal stays a refusal, and the
bytes of an unparsable file stay untouched. Only the message changes;
a settings file that is not an object keeps its own message.

The new tests cover the reported path, the file left in place with its
bytes kept, the refused write, and a valid file read and written as
before.
@brynne8
brynne8 force-pushed the fix/settings-error-names-the-file branch from de4660b to f2021ed Compare October 20, 2026 02:07
@agegr

agegr commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Thanks @brynne8, this is exactly the narrow version I had in mind.

Checked on a merge with current main: the error stays a SyntaxError, the file and its bytes stay where they are, writes are still refused, and the message now leads with the path in the same <path>: <message> form the Plugins route uses. The callers (/api/tools/settings, /api/cache-miss-notices, the MCP Code mode rows) pass the message through unchanged, so all of them name the file now. tsc --noEmit, npm run lint and npm test (2873 pass, 1 skipped) are clean.

Looks good to merge.

@agegr
agegr merged commit 17f104e into agegr:main Oct 29, 2026
2 checks passed
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…#1349)

A global `settings.json` that does not parse is reported with the
parser's own text alone, so the diagnostic does not say which file is
broken. The message now names the path, in the `<path>: <parse error>`
form the Plugins route already uses for pi's settings errors.

The file is not moved, renamed or repaired. `settings.json` belongs to
pi's `SettingsManager`, which reads and writes the same file: when pi
cannot parse it, pi reports the error, leaves the file where it is and
skips every write until the user repairs it by hand. Pi Web keeps
refusing too, and now says which file the user has to repair. Moving
the file aside would let the next write create a fresh `settings.json`
holding one key, which pi would read as a valid file with no
`defaultModel`, no `enabledModels` and no `packages` — and report no
error at all.

The error stays a `SyntaxError`, the refusal stays a refusal, and the
bytes of an unparsable file stay untouched. Only the message changes;
a settings file that is not an object keeps its own message.

The new tests cover the reported path, the file left in place with its
bytes kept, the refused write, and a valid file read and written as
before.
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…#1349)

A global `settings.json` that does not parse is reported with the
parser's own text alone, so the diagnostic does not say which file is
broken. The message now names the path, in the `<path>: <parse error>`
form the Plugins route already uses for pi's settings errors.

The file is not moved, renamed or repaired. `settings.json` belongs to
pi's `SettingsManager`, which reads and writes the same file: when pi
cannot parse it, pi reports the error, leaves the file where it is and
skips every write until the user repairs it by hand. Pi Web keeps
refusing too, and now says which file the user has to repair. Moving
the file aside would let the next write create a fresh `settings.json`
holding one key, which pi would read as a valid file with no
`defaultModel`, no `enabledModels` and no `packages` — and report no
error at all.

The error stays a `SyntaxError`, the refusal stays a refusal, and the
bytes of an unparsable file stay untouched. Only the message changes;
a settings file that is not an object keeps its own message.

The new tests cover the reported path, the file left in place with its
bytes kept, the refused write, and a valid file read and written as
before.
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…#1349)

A global `settings.json` that does not parse is reported with the
parser's own text alone, so the diagnostic does not say which file is
broken. The message now names the path, in the `<path>: <parse error>`
form the Plugins route already uses for pi's settings errors.

The file is not moved, renamed or repaired. `settings.json` belongs to
pi's `SettingsManager`, which reads and writes the same file: when pi
cannot parse it, pi reports the error, leaves the file where it is and
skips every write until the user repairs it by hand. Pi Web keeps
refusing too, and now says which file the user has to repair. Moving
the file aside would let the next write create a fresh `settings.json`
holding one key, which pi would read as a valid file with no
`defaultModel`, no `enabledModels` and no `packages` — and report no
error at all.

The error stays a `SyntaxError`, the refusal stays a refusal, and the
bytes of an unparsable file stay untouched. Only the message changes;
a settings file that is not an object keeps its own message.

The new tests cover the reported path, the file left in place with its
bytes kept, the refused write, and a valid file read and written as
before.
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.

2 participants