Skip to content

Commit

Permalink
Handle missing cargo installs gracefully
Browse files Browse the repository at this point in the history
fixes #17
  • Loading branch information
Swatinem committed May 30, 2021
1 parent ebd9545 commit 31c41a9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@ export async function getCacheConfig(): Promise<CacheConfig> {
}

export async function getCargoBins(): Promise<Set<string>> {
const { installs }: { installs: { [key: string]: { bins: Array<string> } } } = JSON.parse(
await fs.promises.readFile(path.join(paths.cargoHome, ".crates2.json"), "utf8"),
);
const bins = new Set<string>();
for (const pkg of Object.values(installs)) {
for (const bin of pkg.bins) {
bins.add(bin);
try {
const { installs }: { installs: { [key: string]: { bins: Array<string> } } } = JSON.parse(
await fs.promises.readFile(path.join(paths.cargoHome, ".crates2.json"), "utf8"),
);
const bins = new Set<string>();
for (const pkg of Object.values(installs)) {
for (const bin of pkg.bins) {
bins.add(bin);
}
}
return bins;
} catch {
return new Set<string>();
}
return bins;
}

async function getRustKey(): Promise<string> {
Expand Down

0 comments on commit 31c41a9

Please sign in to comment.