Skip to content

Commit 2916417

Browse files
author
Akos Kitta
committed
Handle error when recent-sketches is missing.
Signed-off-by: Akos Kitta <[email protected]>
1 parent a54acce commit 2916417

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Diff for: arduino-ide-extension/src/node/sketches-service-impl.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,22 @@ export class SketchesServiceImpl
230230
private async loadRecentSketches(): Promise<Record<string, number>> {
231231
const fsPath = await this.recentSketchesFsPath;
232232
let data: Record<string, number> = {};
233-
const raw = await fs.readFile(fsPath, {
234-
encoding: 'utf8',
235-
});
236233
try {
237-
data = JSON.parse(raw);
234+
const raw = await fs.readFile(fsPath, {
235+
encoding: 'utf8',
236+
});
237+
try {
238+
data = JSON.parse(raw);
239+
} catch (err) {
240+
console.error(
241+
`Could not parse recently opened sketches. Raw input was: ${raw}`
242+
);
243+
}
238244
} catch (err) {
239-
console.error(
240-
`Could not parse recently opened sketches. Raw input was: ${raw}`
241-
);
245+
if ('code' in err && err.code === 'ENOENT') {
246+
return {};
247+
}
248+
throw err;
242249
}
243250
return data;
244251
}

0 commit comments

Comments
 (0)