diff --git a/src/util.ts b/src/util.ts index f6258b2853..dcd81f4655 100644 --- a/src/util.ts +++ b/src/util.ts @@ -84,9 +84,11 @@ export async function withTmpDir( body: (tmpDir: string) => Promise, ): Promise { const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "codeql-action-")); - const result = await body(tmpDir); - await fs.promises.rm(tmpDir, { force: true, recursive: true }); - return result; + try { + return await body(tmpDir); + } finally { + await fs.promises.rm(tmpDir, { force: true, recursive: true }); + } } /**