{"record":{"id":"123426cd7287c3d4","repo":"remotion-dev/remotion","slug":"deploying-the-site-failed-and-removing-the-genera","errorCode":null,"errorMessage":"Deploying the site failed, and removing the generated bundle also failed.","messagePattern":"Deploying the site failed, and removing the generated bundle also failed\\.","errorType":"exception","errorClass":"AggregateError","httpStatus":null,"severity":"error","filePath":"packages/lambda/src/api/deploy-site.ts","lineNumber":152,"sourceCode":"\t}\n\n\tlet cleanupFailed = false;\n\tlet cleanupError: unknown;\n\tif (generatedBundleDir !== null) {\n\t\ttry {\n\t\t\tfs.rmSync(generatedBundleDir, {\n\t\t\t\tforce: true,\n\t\t\t\trecursive: true,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tcleanupFailed = true;\n\t\t\tcleanupError = error;\n\t\t}\n\t}\n\n\tif (deploymentOutcome.type === 'failure') {\n\t\tif (cleanupFailed) {\n\t\t\tthrow new AggregateError(\n\t\t\t\t[deploymentOutcome.error, cleanupError],\n\t\t\t\t'Deploying the site failed, and removing the generated bundle also failed.',\n\t\t\t\t{cause: deploymentOutcome.error},\n\t\t\t);\n\t\t}\n\n\t\tthrow deploymentOutcome.error;\n\t}\n\n\tif (cleanupFailed) {\n\t\tthrow cleanupError;\n\t}\n\n\treturn deploymentOutcome.result;\n};\n\nexport type InternalDeploySiteInput = MandatoryParameters &\n\tOptionalParameters & {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/lambda/src/api/deploy-site.ts#L134-L170","documentation":"When deploySite() fails to upload the bundle to S3 and the subsequent cleanup (fs.rmSync of the generated bundle directory) also fails, Remotion throws an AggregateError wrapping both the deployment error and the cleanup error. This ensures the original failure is not masked and the cleanup failure is surfaced. If cleanup succeeds, only the original deployment error is thrown.","triggerScenarios":"Calling deploySite() where the S3 upload step fails (network, permissions, bucket issue) AND the code that tries to delete the temporary generated bundle directory on disk also throws (permissions, file lock, already removed).","commonSituations":"S3 permissions insufficient for the upload while a file lock or permission issue prevents deleting the temp bundle; disk full during upload causing both upload failure and cleanup failure; running in a restricted container where both S3 access and temp file deletion are blocked.","solutions":["Inspect the AggregateError.errors array — the first element is the original deployment failure (fix that first), the second is the cleanup failure.","Fix the S3/CloudFront deployment issue (credentials, bucket name, permissions) that caused the upload to fail.","Manually remove the generated bundle directory if cleanup failed, then retry deploySite().","Ensure the temp directory used for bundle generation is writable and deletable by the process."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isAggregateError(err: unknown): err is AggregateError {\n  return err instanceof AggregateError || (err instanceof Error && Array.isArray((err as any).errors));\n}","tryCatchPattern":"try {\n  await deploySite({region, ...});\n} catch (err) {\n  if (err instanceof AggregateError) {\n    const [deployError, cleanupError] = err.errors;\n    console.error('Deploy failed:', deployError);\n    console.error('Cleanup also failed:', cleanupError);\n    // Manually clean up the bundle dir if possible, then retry deploySite()\n  }\n  throw err;\n}","preventionTips":["Verify S3 upload permissions before deploySite() to prevent the primary failure.","Ensure the temp directory is writable and not locked by another process.","Run deploySite() with sufficient disk space for the bundle.","If using a CI runner, confirm it has permissions to create and delete files in its temp dir."],"tags":["lambda","aws","s3","deployment","aggregate-error","cleanup","filesystem"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}