diff --git a/consumer-server/src/logic/lod-generator.ts b/consumer-server/src/logic/lod-generator.ts index 012d77fe..7a8a0a60 100644 --- a/consumer-server/src/logic/lod-generator.ts +++ b/consumer-server/src/logic/lod-generator.ts @@ -38,8 +38,7 @@ export function createLodGeneratorComponent({ logs }: Pick { childProcess.on('error', (error) => { - const generatedFiles = fs.readdirSync(processOutput) - const logFile = generatedFiles.find((file) => file.endsWith('output.txt')) || '' + const logFile = fs.existsSync(processOutput) ? fs.readdirSync(processOutput).find((file) => file.endsWith('output.txt')) || '' : '' resolve({ error: { @@ -53,6 +52,19 @@ export function createLodGeneratorComponent({ logs }: Pick { + if (!fs.existsSync(processOutput)) { + resolve({ + error: { + message: 'Output directory does not exist', + detailedError: `Directory ${processOutput} was not created` + }, + lodsFiles: [], + logFile: '', + outputPath: processOutput + }) + return + } + const generatedFiles = fs.readdirSync(processOutput) const logFile = generatedFiles.find((file) => file.endsWith('output.txt')) || '' if (code !== 0) { diff --git a/consumer-server/src/logic/message-processor.ts b/consumer-server/src/logic/message-processor.ts index f6e2b391..9997c834 100644 --- a/consumer-server/src/logic/message-processor.ts +++ b/consumer-server/src/logic/message-processor.ts @@ -121,8 +121,12 @@ export async function createMessageProcesorComponent({ base, attempt: retry + 1 }) - await storage.storeFiles([lodGenerationResult.logFile], `failures/${base}`) - metrics.increment('lod_generation_count', { status: 'failed' }, 1) + + if (!!lodGenerationResult.logFile) { + logger.debug(`Output file exists, uploading it to the bucket`) + await storage.storeFiles([lodGenerationResult.logFile], `failures/${base}`) + metrics.increment('lod_generation_count', { status: 'failed' }, 1) + } } await queue.deleteMessage(receiptMessageHandle) diff --git a/consumer-server/test/unit/message-processor.spec.ts b/consumer-server/test/unit/message-processor.spec.ts index d46f1cdb..5813bb96 100644 --- a/consumer-server/test/unit/message-processor.spec.ts +++ b/consumer-server/test/unit/message-processor.spec.ts @@ -61,7 +61,7 @@ describe('message-processor', () => { const components = getMessageProcessorMockComponents() components.lodGenerator.generate.mockResolvedValue({ lodsFiles: [], - logFile: '', + logFile: 'somefile', error: { message: 'Error message', detailedError: 'Detailed error message' @@ -85,7 +85,7 @@ describe('message-processor', () => { await messageProcessor.process(message, 'receiptHandle-3') expect(components.queue.deleteMessage).toHaveBeenCalledWith('receiptHandle-3') - expect(components.storage.storeFiles).toHaveBeenCalledWith([''], 'failures/0,0') + expect(components.storage.storeFiles).toHaveBeenCalledWith(['somefile'], 'failures/0,0') expect(components.queue.send).not.toHaveBeenCalled() })