Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2916417

Browse files
author
Akos Kitta
committed
Handle error when recent-sketches is missing.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent a54acce commit 2916417

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

‎arduino-ide-extension/src/node/sketches-service-impl.ts‎

Lines changed: 14 additions & 7 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /