Skip to content

Commit

Permalink
Log error when a file has been created without URL or without Filename (
Browse files Browse the repository at this point in the history
#7396)

we have detected this cases on the db and this will help identify how
this happens
  • Loading branch information
daneryl authored Oct 22, 2024
1 parent 73a79b1 commit 24ce6b3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/api/files/files.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 };
Expand All @@ -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 }));
}

Expand Down

0 comments on commit 24ce6b3

Please sign in to comment.