From 24ce6b3e422ec19da50722edd8034a4cf2da2586 Mon Sep 17 00:00:00 2001 From: Joan Gallego Girona Date: Tue, 22 Oct 2024 08:52:00 +0000 Subject: [PATCH] Log error when a file has been created without URL or without Filename (#7396) we have detected this cases on the db and this will help identify how this happens --- app/api/files/files.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/api/files/files.ts b/app/api/files/files.ts index 1ceccd52b9..1c91d0c9ce 100644 --- a/app/api/files/files.ts +++ b/app/api/files/files.ts @@ -1,9 +1,10 @@ import entities from 'api/entities'; import { applicationEventsBus } from 'api/eventsbus'; import { mimeTypeFromUrl } from 'api/files/extensionHelper'; -import { cleanupRecordsOfFiles } from 'api/services/ocr/ocrRecords'; +import { DefaultLogger } from 'api/log.v2/infrastructure/StandardLogger'; import connections from 'api/relationships'; import { search } from 'api/search'; +import { cleanupRecordsOfFiles } from 'api/services/ocr/ocrRecords'; import { validateFile } from 'shared/types/fileSchema'; import { FileType } from 'shared/types/fileType'; import { FileCreatedEvent } from './events/FileCreatedEvent'; @@ -12,6 +13,7 @@ import { FileUpdatedEvent } from './events/FileUpdatedEvent'; import { filesModel } from './filesModel'; import { storage } from './storage'; import { V2 } from './v2_support'; +import { inspect } from 'util'; const deduceMimeType = (_file: FileType) => { const file = { ..._file }; @@ -38,6 +40,12 @@ export const files = { new FileUpdatedEvent({ before: existingFile, after: savedFile }) ); } else { + if (!savedFile.url && !savedFile.filename) { + DefaultLogger().error([ + inspect(new Error('[Files] a file was created without url or filename')), + inspect(savedFile), + ]); + } await applicationEventsBus.emit(new FileCreatedEvent({ newFile: savedFile })); }