Message fixes (#16389)

In this PR:
- add more logs to troubleshoot issues in production
- use messageChannelSyncStatus in messageSync service instead of making
a manual update
This commit is contained in:
Charles Bochet
2025-12-08 14:56:43 +01:00
committed by GitHub
parent 5f4c7e016c
commit 2790d5dd93
10 changed files with 30 additions and 13 deletions
@@ -48,6 +48,9 @@ export function formatData<T>(
const fieldMetadata = flatFieldMetadataMaps.byId[fieldMetadataId];
if (!fieldMetadata) {
this.logger.warn(
`Field metadata for field "${key}" is missing in object metadata ${flatObjectMetadata.nameSingular} for data: ${JSON.stringify(data)}`,
);
throw new Error(
`Field metadata for field "${key}" is missing in object metadata ${flatObjectMetadata.nameSingular}`,
);
@@ -4,9 +4,14 @@ import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permi
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
import { ChannelSyncResolver } from 'src/modules/connected-account/channel-sync/channel-sync.resolver';
import { ChannelSyncService } from 'src/modules/connected-account/channel-sync/services/channel-sync.service';
import { MessagingCommonModule } from 'src/modules/messaging/common/messaging-common.module';
@Module({
imports: [PermissionsModule, WorkspaceDataSourceModule],
imports: [
PermissionsModule,
WorkspaceDataSourceModule,
MessagingCommonModule,
],
providers: [ChannelSyncResolver, ChannelSyncService],
exports: [ChannelSyncService],
})
@@ -13,9 +13,9 @@ import {
CalendarChannelSyncStatus,
type CalendarChannelWorkspaceEntity,
} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity';
import { MessageChannelSyncStatusService } from 'src/modules/messaging/common/services/message-channel-sync-status.service';
import {
MessageChannelSyncStage,
MessageChannelSyncStatus,
type MessageChannelWorkspaceEntity,
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import {
@@ -36,6 +36,7 @@ export class ChannelSyncService {
private readonly messageQueueService: MessageQueueService,
@InjectMessageQueue(MessageQueue.calendarQueue)
private readonly calendarQueueService: MessageQueueService,
private readonly messageChannelSyncStatusService: MessageChannelSyncStatusService,
) {}
async startChannelSync(input: StartChannelSyncInput): Promise<void> {
@@ -63,10 +64,10 @@ export class ChannelSyncService {
});
for (const messageChannel of messageChannels) {
await messageChannelRepository.update(messageChannel.id, {
syncStage: MessageChannelSyncStage.MESSAGE_LIST_FETCH_SCHEDULED,
syncStatus: MessageChannelSyncStatus.ONGOING,
});
await this.messageChannelSyncStatusService.markAsMessagesListFetchScheduled(
[messageChannel.id],
workspaceId,
);
await this.messageQueueService.add<MessagingMessageListFetchJobData>(
MessagingMessageListFetchJob.name,
@@ -16,7 +16,9 @@ export class GmailFoldersErrorHandlerService {
constructor() {}
public handleError(error: unknown): void {
this.logger.error(`Gmail: Error fetching folders: ${error}`);
this.logger.error(
`Gmail: Error fetching folders: ${JSON.stringify(error)}`,
);
if (isGmailNetworkError(error)) {
throw parseGmailNetworkError(error);
}
@@ -16,7 +16,9 @@ export class GmailMessageListFetchErrorHandler {
constructor() {}
public handleError(error: unknown): void {
this.logger.error(`Gmail: Error fetching message list: ${error}`);
this.logger.error(
`Gmail: Error fetching message list: ${JSON.stringify(error)}`,
);
if (isGmailNetworkError(error)) {
throw parseGmailNetworkError(error);
}
@@ -18,7 +18,9 @@ export class GmailMessagesImportErrorHandler {
constructor() {}
public handleError(error: unknown, messageExternalId: string): void {
this.logger.error(`Gmail: Error importing messages: ${error}`);
this.logger.error(
`Gmail: Error importing messages: ${JSON.stringify(error)}`,
);
if (isGmailNetworkError(error)) {
throw parseGmailNetworkError(error);
@@ -8,7 +8,9 @@ export class ImapMessageListFetchErrorHandler {
private readonly logger = new Logger(ImapMessageListFetchErrorHandler.name);
public handleError(error: Error): void {
this.logger.error(`IMAP: Error fetching message list: ${error.message}`);
this.logger.error(
`IMAP: Error fetching message list: ${JSON.stringify(error)}`,
);
const networkError = parseImapError(error, { cause: error });
@@ -9,7 +9,7 @@ export class ImapMessagesImportErrorHandler {
public handleError(error: Error, messageExternalId: string): void {
this.logger.error(
`IMAP: Error importing message ${messageExternalId}: ${error.message}`,
`IMAP: Error importing message ${messageExternalId}: ${JSON.stringify(error)}`,
);
const networkError = parseImapError(error, { cause: error });
@@ -15,7 +15,7 @@ export class MicrosoftMessageListFetchErrorHandler {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public handleError(error: any): void {
this.logger.log(`Error fetching message list`, error);
this.logger.log(`Error fetching message list: ${JSON.stringify(error)}`);
const networkError = this.microsoftNetworkErrorHandler.handleError(error);
@@ -15,7 +15,7 @@ export class MicrosoftMessagesImportErrorHandler {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public handleError(error: any): void {
this.logger.log(`Error fetching messages`, error);
this.logger.log(`Error fetching messages: ${JSON.stringify(error)}`);
const networkError = this.microsoftNetworkErrorHandler.handleError(error);