Include underlying error in error message

This commit is contained in:
Henry Mercer 2024-06-12 13:44:04 +01:00
parent c8fb403f2f
commit 3d849e9df2
6 changed files with 23 additions and 10 deletions

8
lib/init.test.js generated
View file

@ -93,10 +93,14 @@ for (const { runnerEnv, ErrorConstructor, message } of [
fs.mkdirSync(dbLocation, { recursive: true });
const fileToCleanUp = path_1.default.resolve(dbLocation, "something-to-cleanup.txt");
fs.writeFileSync(fileToCleanUp, "");
const rmSyncError = `Failed to clean up file ${fileToCleanUp}`;
const messages = [];
t.throws(() => (0, init_1.cleanupDatabaseClusterDirectory)((0, testing_utils_1.createTestConfig)({ dbLocation }), (0, testing_utils_1.getRecordingLogger)(messages), () => {
throw new Error("Failed to clean up");
}), { instanceOf: ErrorConstructor, message: message(dbLocation) });
throw new Error(rmSyncError);
}), {
instanceOf: ErrorConstructor,
message: `${message(dbLocation)} Details: ${rmSyncError}`,
});
t.is(messages.length, 1);
t.is(messages[0].type, "warning");
t.is(messages[0].message, `The database cluster directory ${dbLocation} must be empty. Attempting to clean it up.`);