Skip to content

Log routes on file recovery after JSON parse error#1713

Merged
typicode merged 2 commits intomainfrom
copilot/update-json-server-logging
Feb 25, 2026
Merged

Log routes on file recovery after JSON parse error#1713
typicode merged 2 commits intomainfrom
copilot/update-json-server-logging

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

When the watched db file has a JSON parse error and is subsequently fixed, routes were silently not logged if the endpoints hadn't changed — leaving no confirmation that the server recovered.

Changes

  • src/bin.ts: Introduce a hadReadError boolean flag alongside the existing writing/prevEndpoints state.
    • Set hadReadError = true in the SyntaxError catch block of db.read().
    • In observer.onReadEnd, trigger logRoutes(data) when hadReadError is set, regardless of whether prevEndpoints === nextEndpoints.
    • Reset hadReadError = false at the end of onReadEnd after a successful read.
observer.onReadEnd = (data) => {
  if (data === null) return;
  const nextEndpoints = JSON.stringify(Object.keys(data).sort());
  if (hadReadError || prevEndpoints !== nextEndpoints) {
    console.log();
    logRoutes(data);
  }
  hadReadError = false;
};
Original prompt

Update json-server so that after a JSON parse error in the watched db file, routes are logged once upon recovery even if endpoints are unchanged. Implement this by tracking a hadReadError flag in src/bin.ts, setting it when db.read() throws SyntaxError, and using it in observer.onReadEnd to trigger logRoutes(data) even when prevEndpoints === nextEndpoints, then reset the flag on successful read. Do not add any // NEW comments or similar in the code changes.

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: typicode <5502029+typicode@users.noreply.github.com>
Copilot AI changed the title [WIP] Update json-server to log routes on recovery from parse errors Log routes on file recovery after JSON parse error Feb 25, 2026
Copilot AI requested a review from typicode February 25, 2026 15:01
@typicode typicode marked this pull request as ready for review February 25, 2026 15:10
@typicode typicode merged commit 9df3716 into main Feb 25, 2026
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