Skip to content

Commit

Permalink
chore: add more logging to perserveFilesForDebugging
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Dec 15, 2024
1 parent 231ea87 commit 52c07f4
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/lib/debug/perserveFilesForDebugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,26 @@ export function perserveFilesForDebugging(
) {
const debugDirectory = path.join(os.tmpdir(), 'debug', getRandomUUID());

if (!fs.existsSync(debugDirectory)) {
try {
try {
if (!fs.existsSync(debugDirectory)) {
fs.mkdirSync(debugDirectory, { recursive: true });
console.log(`Created debug directory: ${debugDirectory}`);
} catch (error) {
console.error(`Failed to create debug directory: ${error}`);
return;
}
}

const timestamp = new Date().toISOString();
const errorMessage = `${timestamp} - ${err.name}: \n${err.message}\n${err.stack}`;
fs.writeFileSync(`${debugDirectory}/error.txt`, errorMessage);
uploadedFiles.forEach((file, index) => {
try {
const destPath = `${debugDirectory}/${index}-${path.basename(
file.originalname
)}`;
const timestamp = new Date().toISOString();
const errorMessage = `${timestamp} - ${err.name}: \n${err.message}\n${err.stack}`;
fs.writeFileSync(`${debugDirectory}/error.txt`, errorMessage);

uploadedFiles.forEach((file, index) => {
const destPath = path.join(
debugDirectory,
`${index}-${path.basename(file.originalname)}`
);
const fileContents = fs.readFileSync(file.path);
fs.writeFileSync(destPath, fileContents);
console.log(`Copied file ${file.path} to ${destPath}`);
} catch (error) {
console.error(`Error copying file ${file.path}: ${error}`);
}
});
});
} catch (error) {
console.error(`Error in perserveFilesForDebugging: ${error}`);
}
}

0 comments on commit 52c07f4

Please sign in to comment.