From 31c41a926e24c7cdb79b06151fcee21d0b459722 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Sun, 30 May 2021 10:55:21 +0200 Subject: [PATCH] Handle missing cargo installs gracefully fixes #17 --- src/common.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/common.ts b/src/common.ts index f7ab2ed..8ee4c47 100644 --- a/src/common.ts +++ b/src/common.ts @@ -86,16 +86,20 @@ export async function getCacheConfig(): Promise { } export async function getCargoBins(): Promise> { - const { installs }: { installs: { [key: string]: { bins: Array } } } = JSON.parse( - await fs.promises.readFile(path.join(paths.cargoHome, ".crates2.json"), "utf8"), - ); - const bins = new Set(); - for (const pkg of Object.values(installs)) { - for (const bin of pkg.bins) { - bins.add(bin); + try { + const { installs }: { installs: { [key: string]: { bins: Array } } } = JSON.parse( + await fs.promises.readFile(path.join(paths.cargoHome, ".crates2.json"), "utf8"), + ); + const bins = new Set(); + for (const pkg of Object.values(installs)) { + for (const bin of pkg.bins) { + bins.add(bin); + } } + return bins; + } catch { + return new Set(); } - return bins; } async function getRustKey(): Promise {