Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions ee/packages/federation-matrix/src/FederationMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

return matrixRoomResult;
} catch (error) {
this.logger.error('Failed to create room:', error);
this.logger.error(error, 'Failed to create room');
throw error;
}
}
Expand All @@ -260,7 +260,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
});
}
} catch (error) {
this.logger.error({ msg: 'Failed to ensure federated users exist locally', error });
this.logger.error(error, 'Failed to ensure federated users exist locally');
throw error;
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
userIdSchema.parse(actualMatrixUserId),
);
} catch (error) {
this.logger.error('Error creating or updating bridged user for DM:', error);
this.logger.error(error, 'Error creating or updating bridged user for DM');
}
}
}
Expand All @@ -320,9 +320,9 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
mrid: matrixRoomResult.room_id,
origin: this.serverName,
});
this.logger.debug('Direct message room creation completed successfully', room._id);
this.logger.debug({ roomId: room._id, msg: 'Direct message room creation completed successfully' });
} catch (error) {
this.logger.error('Failed to create direct message room:', error);
this.logger.error(error, 'Failed to create direct message room');
throw error;
}
}
Expand Down Expand Up @@ -376,9 +376,10 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

return lastEventId;
} catch (error) {
this.logger.error('Failed to handle file message', {
this.logger.error({
msg: 'Failed to handle file message',
messageId: message._id,
error,
err: error,
});
throw error;
}
Expand Down Expand Up @@ -473,7 +474,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

this.logger.debug('Message sent to Matrix successfully:', result.eventId);
} catch (error) {
this.logger.error('Failed to send message to Matrix:', error);
this.logger.error(error, 'Failed to send message to Matrix');
throw error;
}
}
Expand Down Expand Up @@ -535,7 +536,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

this.logger.debug('Message Redaction sent to Matrix successfully:', eventId);
} catch (error) {
this.logger.error('Failed to send redaction to Matrix:', error);
this.logger.error(error, 'Failed to send redaction to Matrix');
throw error;
}
}
Expand Down Expand Up @@ -571,7 +572,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
}),
);
} catch (error) {
this.logger.error({ msg: 'Failed to invite an user to Matrix:', err: error });
this.logger.error(error, 'Failed to invite a user to Matrix');
throw error;
}
}
Expand Down Expand Up @@ -606,9 +607,9 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

await Messages.setFederationReactionEventId(user.username || '', messageId, reaction, eventId);

this.logger.debug('Reaction sent to Matrix successfully:', eventId);
this.logger.debug({ eventId, msg: 'Reaction sent to Matrix successfully' });
} catch (error) {
this.logger.error('Failed to send reaction to Matrix:', error);
this.logger.error(error, 'Failed to send reaction to Matrix');
throw error;
}
}
Expand All @@ -617,7 +618,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
try {
const message = await Messages.findOneById(messageId);
if (!message) {
this.logger.error(`Message ${messageId} not found`);
this.logger.error({ messageId, msg: 'Message not found' });
return;
}

Expand All @@ -629,7 +630,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

const room = await Rooms.findOneById(message.rid);
if (!room || !isRoomNativeFederated(room)) {
this.logger.error(`No Matrix room mapping found for room ${message.rid}`);
this.logger.error({ rid: message.rid, msg: 'No Matrix room mapping found for room' });
return;
}

Expand Down Expand Up @@ -662,7 +663,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
break;
}
} catch (error) {
this.logger.error('Failed to remove reaction from Matrix:', error);
this.logger.error(error, 'Failed to remove reaction from Matrix');
throw error;
}
}
Expand Down Expand Up @@ -690,7 +691,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

this.logger.info(`User ${user.username} left Matrix room ${room.federation.mrid} successfully`);
} catch (error) {
this.logger.error('Failed to leave room in Matrix:', error);
this.logger.error(error, 'Failed to leave room in Matrix');
throw error;
}
}
Expand All @@ -714,7 +715,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

this.logger.info(`User ${removedUser.username} was kicked from Matrix room ${room.federation.mrid} by ${userWhoRemoved.username}`);
} catch (error) {
this.logger.error('Failed to kick user from Matrix room:', error);
this.logger.error(error, 'Failed to kick user from Matrix room');
throw error;
}
}
Expand All @@ -728,7 +729,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

const user = await Users.findOneById(message.u._id, { projection: { _id: 1, username: 1, federation: 1, federated: 1 } });
if (!user) {
this.logger.error(`No user found for ID ${message.u._id}`);
this.logger.error({ userId: message.u._id, msg: 'No user found for ID' });
return;
}

Expand All @@ -749,7 +750,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS

this.logger.debug('Message updated in Matrix successfully:', eventId);
} catch (error) {
this.logger.error('Failed to update message in Matrix:', error);
this.logger.error(error, 'Failed to update message in Matrix');
throw error;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ee/packages/federation-matrix/src/api/_matrix/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ async function runWithBackoff(fn: () => Promise<void>, delaySec = 5) {
} catch (e) {
// don't retry on authorization/validation errors - they won't succeed on retry
if (e instanceof NotAllowedError) {
logger.error('Authorization error, not retrying:', e);
logger.error(e, 'Authorization error, not retrying');
return;
}

const delay = Math.min(625, delaySec ** 2);
logger.error(`error occurred, retrying in ${delay}s`, e);
logger.error(e, `error occurred, retrying in ${delay}s`);
setTimeout(() => {
runWithBackoff(fn, delay);
}, delay * 1000);
Expand Down
4 changes: 2 additions & 2 deletions ee/packages/federation-matrix/src/events/edu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const edus = async (emitter: Emitter<HomeserverEventSignatures>) => {
roomId: matrixRoom._id,
});
} catch (error) {
logger.error('Error handling Matrix typing event:', error);
logger.error(error, 'Error handling Matrix typing event');
}
});

Expand Down Expand Up @@ -79,7 +79,7 @@ export const edus = async (emitter: Emitter<HomeserverEventSignatures>) => {
});
logger.debug(`Updated presence for user ${matrixUser._id} to ${status} from Matrix federation`);
} catch (error) {
logger.error('Error handling Matrix presence event:', error);
logger.error(error, 'Error handling Matrix presence event');
}
});
};
2 changes: 1 addition & 1 deletion ee/packages/federation-matrix/src/events/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function member(emitter: Emitter<HomeserverEventSignatures>) {

logger.debug(`Ignoring membership event with membership: ${event.content.membership}`);
} catch (error) {
logger.error('Failed to process Matrix membership event:', error);
logger.error(error, 'Failed to process Matrix membership event');
}
});
}
10 changes: 5 additions & 5 deletions ee/packages/federation-matrix/src/events/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function message(emitter: Emitter<HomeserverEventSignatures>) {
logger.debug('Received edited message from Matrix, updating existing message');
const originalMessage = await Messages.findOneByFederationId(relation.event_id);
if (!originalMessage) {
logger.error('Original message not found for edit:', relation.event_id);
logger.error({ event_id: relation.event_id, msg: 'Original message not found for edit' });
return;
}
if (originalMessage.federation?.eventId !== relation.event_id) {
Expand Down Expand Up @@ -216,7 +216,7 @@ export function message(emitter: Emitter<HomeserverEventSignatures>) {
if (quoteMessageEventId) {
const originalMessage = await Messages.findOneByFederationId(quoteMessageEventId);
if (!originalMessage) {
logger.error('Original message not found for quote:', quoteMessageEventId);
logger.error({ quoteMessageEventId, msg: 'Original message not found for quote' });
return;
}
const messageToReplyToUrl = await MeteorService.getMessageURLToReplyTo(room.t as string, room._id, originalMessage._id);
Expand Down Expand Up @@ -311,7 +311,7 @@ export function message(emitter: Emitter<HomeserverEventSignatures>) {
logger.debug('Received edited message from Matrix, updating existing message');
const originalMessage = await Messages.findOneByFederationId(relation.event_id);
if (!originalMessage) {
logger.error('Original message not found for edit:', relation.event_id);
logger.error({ event_id: relation.event_id, msg: 'Original message not found for edit' });
return;
}
if (originalMessage.federation?.eventId !== relation.event_id) {
Expand Down Expand Up @@ -354,7 +354,7 @@ export function message(emitter: Emitter<HomeserverEventSignatures>) {
if (quoteMessageEventId) {
const originalMessage = await Messages.findOneByFederationId(quoteMessageEventId);
if (!originalMessage) {
logger.error('Original message not found for quote:', quoteMessageEventId);
logger.error({ quoteMessageEventId, msg: 'Original message not found for quote' });
return;
}
await Message.saveMessageFromFederation({
Expand Down Expand Up @@ -413,7 +413,7 @@ export function message(emitter: Emitter<HomeserverEventSignatures>) {

await Message.deleteMessage(user, rcMessage);
} catch (error) {
logger.error('Failed to process Matrix removal redaction:', error);
logger.error(error, 'Failed to process Matrix removal redaction');
}
});
}
8 changes: 4 additions & 4 deletions ee/packages/federation-matrix/src/events/reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export function reaction(emitter: Emitter<HomeserverEventSignatures>) {

const [userPart, domain] = event.sender.split(':');
if (!userPart || !domain) {
logger.error('Invalid Matrix sender ID format:', event.sender);
logger.error({ sender: event.sender, msg: 'Invalid Matrix sender ID format' });
return;
}

const internalUsername = event.sender;
const user = await Users.findOneByUsername(internalUsername);
if (!user) {
logger.error(`No RC user mapping found for Matrix event ${reactionTargetEventId} ${internalUsername}`);
logger.error({ reactionTargetEventId, internalUsername, msg: 'No RC user mapping found for Matrix event' });
return;
}

Expand All @@ -43,7 +43,7 @@ export function reaction(emitter: Emitter<HomeserverEventSignatures>) {
await Message.reactToMessage(user._id, reactionEmoji, rcMessage._id, true);
await Messages.setFederationReactionEventId(internalUsername, rcMessage._id, reactionEmoji, eventId);
} catch (error) {
logger.error('Failed to process Matrix reaction:', error);
logger.error(error, 'Failed to process Matrix reaction');
}
});

Expand Down Expand Up @@ -87,7 +87,7 @@ export function reaction(emitter: Emitter<HomeserverEventSignatures>) {
await Message.reactToMessage(user._id, reactionEmoji, rcMessage._id, false);
await Messages.unsetFederationReactionEventId(redactedEventId, rcMessage._id, reactionEmoji);
} catch (error) {
logger.error('Failed to process Matrix reaction redaction:', error);
logger.error(error, 'Failed to process Matrix reaction redaction');
}
});
}
10 changes: 5 additions & 5 deletions ee/packages/federation-matrix/src/services/MatrixMediaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class MatrixMediaService {
static parseMXCUri(mxcUri: string): { serverName: string; mediaId: string } | null {
const match = mxcUri.match(/^mxc:\/\/([^/]+)\/(.+)$/);
if (!match) {
logger.error('Invalid MXC URI format', { mxcUri });
logger.error({ mxcUri, msg: 'Invalid MXC URI format' });
return null;
}
return {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class MatrixMediaService {

return mxcUri;
} catch (error) {
logger.error('Error preparing file for Matrix:', error);
logger.error(error, 'Error preparing file for Matrix');
throw error;
}
}
Expand All @@ -74,7 +74,7 @@ export class MatrixMediaService {

return file;
} catch (error) {
logger.error('Error retrieving local file:', error);
logger.error(error, 'Error retrieving local file');
return null;
}
}
Expand All @@ -94,7 +94,7 @@ export class MatrixMediaService {
try {
const parts = this.parseMXCUri(mxcUri);
if (!parts) {
logger.error('Invalid MXC URI format', { mxcUri });
logger.error({ mxcUri, msg: 'Invalid MXC URI format' });
throw new Error('Invalid MXC URI');
}

Expand Down Expand Up @@ -130,7 +130,7 @@ export class MatrixMediaService {

return uploadedFile._id;
} catch (error) {
logger.error('Error downloading and storing remote file:', error);
logger.error(error, 'Error downloading and storing remote file');
throw error;
}
}
Expand Down
Loading