Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 7631349e84 fix: handle missing FileEntity in copyWorkspaceMemberProfilePicture gracefully
https://sonarly.com/issue/16338?type=bug

When an existing user creates a new workspace, the profile picture copy fails with an unhandled EntityNotFoundError if the source FileEntity record no longer exists in the database, causing the entire SignUpInNewWorkspace mutation to fail.

Fix: **Two changes to fix the `EntityNotFoundError` crash during `SignUpInNewWorkspace`:**

1. **`file-core-picture.service.ts`**: Changed `findOneOrFail` to `findOne` in `copyWorkspaceMemberProfilePicture` (line 281), with an early `return undefined` and `logger.warn` when the source file record doesn't exist. This follows the identical pattern applied to `deleteCorePicture` in the same file (commit cea450cb9b). The return type changes from `Promise<FileWithSignedUrlDTO>` to `Promise<FileWithSignedUrlDTO | undefined>`.

2. **`user-workspace.service.ts`**: Changed `savedFile.url` to `savedFile?.url` (line 472) to safely handle the new `undefined` return from `copyWorkspaceMemberProfilePicture`. When the source file isn't found, the method returns `undefined` as the avatar URL, and workspace creation proceeds without a profile picture — matching the existing behavior when `pictureUrl` is empty or `extractFileIdFromUrl` returns null.

The existing catch block for `FileStorageExceptionCode.FILE_NOT_FOUND` is preserved as it handles a different failure mode (file exists in DB but missing from storage).
2026-03-19 10:51:50 +00:00
2 changed files with 11 additions and 3 deletions
@@ -277,8 +277,8 @@ export class FileCorePictureService {
targetWorkspaceId: string;
targetApplicationUniversalIdentifier?: string;
queryRunner?: QueryRunner;
}): Promise<FileWithSignedUrlDTO> {
const sourceFile = await this.fileRepository.findOneOrFail({
}): Promise<FileWithSignedUrlDTO | undefined> {
const sourceFile = await this.fileRepository.findOne({
where: {
id: sourceFileId,
workspaceId: sourceWorkspaceId,
@@ -286,6 +286,14 @@ export class FileCorePictureService {
},
});
if (!isDefined(sourceFile)) {
this.logger.warn(
`Core picture file not found for copy — sourceFileId: ${sourceFileId}, sourceWorkspaceId: ${sourceWorkspaceId}`,
);
return undefined;
}
const { workspaceCustomFlatApplication: sourceApplication } =
await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
{
@@ -469,7 +469,7 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspaceEntit
queryRunner,
});
return savedFile.url;
return savedFile?.url;
} catch (error) {
if (error.code === FileStorageExceptionCode.FILE_NOT_FOUND) {
return;