From 75c6768f0a678e79ab23bea071eb4b8443507470 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 14 Aug 2024 13:44:02 -0300 Subject: [PATCH] chore: Do not clean up bb files on err (#7985) Even if BB_SKIP_CLEANUP is not set, avoid deleting the tmp dir for bb if the operation fails, so we can retrieve those files later. --- .../bb-prover/src/prover/bb_private_kernel_prover.ts | 11 ++++++++++- yarn-project/bb-prover/src/prover/bb_prover.ts | 10 +++++++++- yarn-project/foundation/src/fs/run_in_dir.ts | 5 ++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts index e451d75746d..250801ed477 100644 --- a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts @@ -366,6 +366,15 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver { } private runInDirectory(fn: (dir: string) => Promise) { - return runInDirectory(this.bbWorkingDirectory, fn, this.skipCleanup); + const log = this.log; + return runInDirectory( + this.bbWorkingDirectory, + (dir: string) => + fn(dir).catch(err => { + log.error(`Error running operation at ${dir}: ${err}`); + throw err; + }), + this.skipCleanup, + ); } } diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index e432628c054..af3c839ff2d 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -956,6 +956,14 @@ export class BBNativeRollupProver implements ServerCircuitProver { } private runInDirectory(fn: (dir: string) => Promise) { - return runInDirectory(this.config.bbWorkingDirectory, fn, this.config.bbSkipCleanup); + return runInDirectory( + this.config.bbWorkingDirectory, + (dir: string) => + fn(dir).catch(err => { + logger.error(`Error running operation at ${dir}: ${err}`); + throw err; + }), + this.config.bbSkipCleanup, + ); } } diff --git a/yarn-project/foundation/src/fs/run_in_dir.ts b/yarn-project/foundation/src/fs/run_in_dir.ts index eb4794c8c64..9ff007a49b6 100644 --- a/yarn-project/foundation/src/fs/run_in_dir.ts +++ b/yarn-project/foundation/src/fs/run_in_dir.ts @@ -2,7 +2,7 @@ import * as fs from 'fs/promises'; import * as path from 'path'; // Create a random directory underneath a 'base' directory -// Calls a provided method, ensures the random directory is cleaned up afterwards +// Calls a provided method, ensures the random directory is cleaned up afterwards unless the operation fails export async function runInDirectory( workingDirBase: string, fn: (dir: string) => Promise, @@ -15,6 +15,9 @@ export async function runInDirectory( try { return await fn(workingDirectory); + } catch (err) { + skipCleanup = true; + throw err; } finally { if (!skipCleanup) { await fs.rm(workingDirectory, { recursive: true, force: true });