From 1463100e6d4a50cad75bb05eae305f54c7d41902 Mon Sep 17 00:00:00 2001 From: Pawzy Date: Sun, 19 Oct 2025 17:52:19 -0500 Subject: [PATCH] Added minor error handling for Userid not found --- .../src/server/api/stream/Connection.ts | 54 ++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/packages/backend/src/server/api/stream/Connection.ts b/packages/backend/src/server/api/stream/Connection.ts index 0ee7078eb2..31ebc894d4 100644 --- a/packages/backend/src/server/api/stream/Connection.ts +++ b/packages/backend/src/server/api/stream/Connection.ts @@ -64,25 +64,41 @@ export default class Connection { this.logger = loggerService.getLogger('streaming', 'coral'); } - @bindThis - public async fetch() { - if (this.user == null) return; - const [userProfile, following, followingChannels, userIdsWhoMeMuting, userIdsWhoBlockingMe, userIdsWhoMeMutingRenotes] = await Promise.all([ - this.cacheService.userProfileCache.fetch(this.user.id), - this.cacheService.userFollowingsCache.fetch(this.user.id), - this.channelFollowingService.userFollowingChannelsCache.fetch(this.user.id), - this.cacheService.userMutingsCache.fetch(this.user.id), - this.cacheService.userBlockedCache.fetch(this.user.id), - this.cacheService.renoteMutingsCache.fetch(this.user.id), - ]); - this.userProfile = userProfile; - this.following = following; - this.followingChannels = followingChannels; - this.userIdsWhoMeMuting = userIdsWhoMeMuting; - this.userIdsWhoBlockingMe = userIdsWhoBlockingMe; - this.userIdsWhoMeMutingRenotes = userIdsWhoMeMutingRenotes; - this.userMutedInstances = new Set(userProfile.mutedInstances); - } +@bindThis + public async fetch() { + if (this.user == null) return; + + try { + const [userProfile, following, followingChannels, userIdsWhoMeMuting, userIdsWhoBlockingMe, userIdsWhoMeMutingRenotes] = await Promise.all([ + this.cacheService.userProfileCache.fetch(this.user.id), + this.cacheService.userFollowingsCache.fetch(this.user.id), + this.channelFollowingService.userFollowingChannelsCache.fetch(this.user.id), + this.cacheService.userMutingsCache.fetch(this.user.id), + this.cacheService.userBlockedCache.fetch(this.user.id), + this.cacheService.renoteMutingsCache.fetch(this.user.id), + ]); + + if (userProfile == null) { + this.logger.warn(`User profile was null for user ${this.user.id}, closing connection.`); + this.wsConnection.close(); + return; + } + this.userProfile = userProfile; + this.following = following; + this.followingChannels = followingChannels; + this.userIdsWhoMeMuting = userIdsWhoMeMuting; + this.userIdsWhoBlockingMe = userIdsWhoBlockingMe; + this.userIdsWhoMeMutingRenotes = userIdsWhoMeMutingRenotes; + this.userMutedInstances = new Set(userProfile.mutedInstances); + } catch (error) { + if (error && typeof error === 'object' && 'name' in error && error.name === 'EntityNotFoundError') { + this.logger.warn(`User profile not found for user ${this.user.id}. Closing connection.`); + } else { + this.logger.error(`An unexpected error occurred during fetch for user ${this.user.id}: ${String(error)}`); + } + this.wsConnection.close(); + } + } @bindThis public async init() {