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

View file

@ -108,6 +108,8 @@ for (const { runnerEnv, ErrorConstructor, message } of [
);
fs.writeFileSync(fileToCleanUp, "");
const rmSyncError = `Failed to clean up file ${fileToCleanUp}`;
const messages: LoggedMessage[] = [];
t.throws(
() =>
@ -115,10 +117,13 @@ for (const { runnerEnv, ErrorConstructor, message } of [
createTestConfig({ dbLocation }),
getRecordingLogger(messages),
() => {
throw new Error("Failed to clean up");
throw new Error(rmSyncError);
},
),
{ instanceOf: ErrorConstructor, message: message(dbLocation) },
{
instanceOf: ErrorConstructor,
message: `${message(dbLocation)} Details: ${rmSyncError}`,
},
);
t.is(messages.length, 1);

View file

@ -210,13 +210,17 @@ export function cleanupDatabaseClusterDirectory(
if (isSelfHostedRunner()) {
throw new util.ConfigurationError(
`${blurb} This can happen if another process is using the directory or the directory is owned by a different user. ` +
"Please clean up the directory manually and rerun the job.",
`Please clean up the directory manually and rerun the job. Details: ${
util.wrapError(e).message
}`,
);
} else {
throw new Error(
`${blurb} This shouldn't typically happen on hosted runners. ` +
"If you are using an advanced setup, please check your workflow, otherwise we " +
"recommend rerunning the job.",
`recommend rerunning the job. Details: ${
util.wrapError(e).message
}`,
);
}
}