Skip to content

Commit 9df3716

Browse files
authored
Log routes on file recovery after JSON parse error (#1713)
1 parent 977a0bf commit 9df3716

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/bin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ app.listen(port, () => {
183183
// Watch file for changes
184184
if (process.env["NODE_ENV"] !== "production") {
185185
let writing = false; // true if the file is being written to by the app
186+
let hadReadError = false;
186187
let prevEndpoints = "";
187188

188189
observer.onWriteStart = () => {
@@ -200,16 +201,18 @@ if (process.env["NODE_ENV"] !== "production") {
200201
}
201202

202203
const nextEndpoints = JSON.stringify(Object.keys(data).sort());
203-
if (prevEndpoints !== nextEndpoints) {
204+
if (hadReadError || prevEndpoints !== nextEndpoints) {
204205
console.log();
205206
logRoutes(data);
206207
}
208+
hadReadError = false;
207209
};
208210
watch(file).on("change", () => {
209211
// Do no reload if the file is being written to by the app
210212
if (!writing) {
211213
db.read().catch((e) => {
212214
if (e instanceof SyntaxError) {
215+
hadReadError = true;
213216
return console.log(chalk.red(["", `Error parsing ${file}`, e.message].join("\n")));
214217
}
215218
console.log(e);

0 commit comments

Comments
 (0)