fix: handle missing file entity in avatar deletion listener (#20192)

## Problem
When a `workspaceMember` is updated (e.g., theme/locale/avatar changes),
the `WorkspaceMemberAvatarFileDeletionListener` triggers file deletion.
If the referenced file entity doesn't exist in the database, an
unhandled `EntityNotFoundError` crashes the NestJS server, causing a 502
loop.

## Change
Wrap the file deletion call in a try-catch that gracefully handles
`EntityNotFoundError` as a no-op — if the file doesn't exist, there's
nothing to delete.

Fixes #20191.

Made with [Cursor](https://cursor.com)

Co-authored-by: martmull <martmull@hotmail.fr>
This commit is contained in:
Ayush Baluni
2026-05-04 20:28:56 +05:30
committed by GitHub
parent 37ca09e8f9
commit 1cd983a330
@@ -1,5 +1,7 @@
import { Injectable } from '@nestjs/common';
import { EntityNotFoundError } from 'typeorm/error/EntityNotFoundError';
import {
ObjectRecordDeleteEvent,
ObjectRecordDestroyEvent,
@@ -29,7 +31,7 @@ export class WorkspaceMemberAvatarFileDeletionListener {
) {
const fileIdsToDelete = this.getFileIdsToDeleteFromUpdateEvent(payload);
this.deleteCorePictures(fileIdsToDelete, payload.workspaceId);
await this.deleteCorePictures(fileIdsToDelete, payload.workspaceId);
}
@OnDatabaseBatchEvent('workspaceMember', DatabaseEventAction.DESTROYED)
@@ -51,10 +53,17 @@ export class WorkspaceMemberAvatarFileDeletionListener {
workspaceId: string,
): Promise<void> {
for (const fileId of fileIds) {
await this.fileCorePictureService.deleteCorePicture({
workspaceId,
fileId,
});
try {
await this.fileCorePictureService.deleteCorePicture({
workspaceId,
fileId,
});
} catch (error) {
if (error instanceof EntityNotFoundError) {
continue;
}
throw error;
}
}
}