Repository: twentyhq/twenty
File: packages/twenty-server/src/database/commands/upgrade-version-command/1-18/1-18-backfill-file-size-and-mime-type.command.ts (TypeScript)

Code before:
            `File ${fileEntity.id} (path: ${fileEntity.path}) not found in storage`,
          );

          continue;
        }

        const fileStream = await this.fileStorageService.readFile({
          fileFolder,
          applicationUniversalIdentifier: application.universalIdentifier,
          workspaceId,
          resourcePath: removeFileFolderFromFileEntityPath(fileEntity.path),
        });

        const fileBuffer = await streamToBuffer(fileStream);

        const updateData: {
          size?: number;
          mimeType?: string;
        } = {};

        if (fileEntity.size < 0) {
          updateData.size = fileBuffer.length;
        }

        if (fileEntity.mimeType === 'application/octet-stream') {
          const { mimeType } = await extractFileInfo({
            file: fileBuffer,
            filename: fileEntity.path,
          });

          updateData.mimeType = mimeType;
        }

        if (!isDryRun) {
          await fileRepository.update({ id: fileEntity.id }, updateData);
        }

        const updateDetails = Object.entries(updateData)
          .map(([key, value]) => `${key}=${value}`)
          .join(', ');

        this.logger.log(
          `${isDryRun ? '[DRY RUN] ' : ''}Backfilled file ${fileEntity.id}: ${updateDetails}`,
        );
      } catch (error) {
        this.logger.error(
          `Failed to backfill file ${fileEntity.id} in workspace ${workspaceId}: ${error.message}`,
        );
      }
    }


Review comment (bug):
***Remark:*** There's a world where we could get such exception here
```ts
      throw new FileStorageException(
        `File content does not match its extension. The file has extension '${ext}' (expected mime type: ${mimeTypeFromExtension}), but the file content could not be detected as this type. The file may be corrupted, have the wrong extension, or be a security risk.`,
        FileStorageExceptionCode.INVALID_EXTENSION,
        {
          userFriendlyMessage: msg`The file extension doesn't match the file content. Please check that your file is not corrupted and has the correct extension.`,
        },
      );
```

Code after:
            `File ${fileEntity.id} (path: ${fileEntity.path}) not found in storage`,
          );

          continue;
        }

        const fileStream = await this.fileStorageService.readFile({
          fileFolder,
          applicationUniversalIdentifier: application.universalIdentifier,
          workspaceId,
          resourcePath: removeFileFolderFromFileEntityPath(fileEntity.path),
        });

        const fileBuffer = await streamToBuffer(fileStream);

        const updateData: {
          size?: number;
          mimeType?: string;
        } = {};

        if (fileEntity.size < 0) {
          updateData.size = fileBuffer.length;
        }

        if (fileEntity.mimeType === 'application/octet-stream') {
          try {
            const { mimeType } = await extractFileInfo({
              file: fileBuffer,
              filename: fileEntity.path,
            });

            updateData.mimeType = mimeType;
          } catch (error) {
            this.logger.error(
              `Failed to extract file mime type for file ${fileEntity.id} in workspace ${workspaceId}: ${error.message}`,
            );

            continue;
          }
        }

        if (!isDryRun) {
          await fileRepository.update({ id: fileEntity.id }, updateData);
        }

        const updateDetails = Object.entries(updateData)
          .map(([key, value]) => `${key}=${value}`)
          .join(', ');

        this.logger.log(
          `${isDryRun ? '[DRY RUN] ' : ''}Backfilled file ${fileEntity.id}: ${updateDetails}`,