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 49248b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 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}`);
}
}
4 changes: 3 additions & 1 deletion src/services/UploadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import express from 'express';

import { IUploadRepository } from '../data_layer/UploadRespository';
import { sendError } from '../lib/error/sendError';
import ErrorHandler, { NO_PACKAGE_ERROR } from '../routes/middleware/ErrorHandler';
import ErrorHandler, {
NO_PACKAGE_ERROR,

Check failure on line 6 in src/services/UploadService.ts

View workflow job for this annotation

GitHub Actions / build (20.18.0)

Module '"../routes/middleware/ErrorHandler"' has no exported member 'NO_PACKAGE_ERROR'. Did you mean to use 'import NO_PACKAGE_ERROR from "../routes/middleware/ErrorHandler"' instead?
} from '../routes/middleware/ErrorHandler';
import Settings from '../lib/parser/Settings';
import Workspace from '../lib/parser/WorkSpace';
import StorageHandler from '../lib/storage/StorageHandler';
Expand Down

0 comments on commit 49248b7

Please sign in to comment.