Skip to content

Commit

Permalink
fix(config): don't abort reading the index when writing fails (#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Feb 23, 2021
1 parent a5c0d8c commit f72e2f4
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/config/src/Devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,24 @@ export async function loadDeviceIndexInternal(
}
}

// Save the index to disk (but not during unit tests)
await writeFile(
path.join(indexPath),
`// This file is auto-generated. DO NOT edit it by hand if you don't know what you're doing!"
// Save the index to disk
try {
await writeFile(
path.join(indexPath),
`// This file is auto-generated. DO NOT edit it by hand if you don't know what you're doing!"
${stringify(index, "\t")}
`,
"utf8",
);
logger?.print("Device index regenerated", "verbose");
"utf8",
);
logger?.print("Device index regenerated", "verbose");
} catch (e: unknown) {
logger?.print(
`Writing the device index to disk failed: ${
(e as Error).message
}`,
"error",
);
}
}

return index!;
Expand Down

0 comments on commit f72e2f4

Please sign in to comment.