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
17 changes: 9 additions & 8 deletions packages/federation-sdk/src/services/event-fetcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ export class EventFetcherService {

return eventsToReturn;
} catch (error: unknown) {
const errorMessage =
error instanceof Error ? error.message : String(error);
this.logger.error(
`Error fetching events from federation: ${errorMessage}`,
);
this.logger.debug(
`Failed federation request details: ${JSON.stringify({ eventIds, targetServerName })}`,
);
this.logger.error({
msg: 'Error fetching events from federation',
err: error,
});
this.logger.debug({
msg: 'Failed federation request details',
eventIds,
targetServerName,
});
return eventsToReturn;
}
}
Expand Down
31 changes: 14 additions & 17 deletions packages/federation-sdk/src/services/federation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class FederationService {
queryParams,
);
} catch (error: any) {
this.logger.error(`makeJoin failed: ${error?.message}`, error?.stack);
this.logger.error({ msg: 'makeJoin failed', err: error });
throw error;
}
}
Expand All @@ -82,7 +82,7 @@ export class FederationService {
const residentServer = joinEvent.roomId.split(':').pop();

if (!residentServer) {
this.logger.debug(joinEvent.event, 'invalid room_id');
this.logger.debug({ msg: 'invalid room_id', event: joinEvent.event });
throw new Error(
`invalid room_id ${joinEvent.roomId}, no server_name part`,
);
Expand All @@ -95,7 +95,7 @@ export class FederationService {
queryParams,
);
} catch (error: any) {
this.logger.error(`sendJoin failed: ${error?.message}`, error?.stack);
this.logger.error({ msg: 'sendJoin failed', err: error });
throw error;
}
}
Expand All @@ -117,10 +117,7 @@ export class FederationService {
transaction,
);
} catch (error: any) {
this.logger.error(
`sendTransaction failed: ${error?.message}`,
error?.stack,
);
this.logger.error({ msg: 'sendTransaction failed', err: error });
throw error;
}
}
Expand All @@ -141,7 +138,7 @@ export class FederationService {

return await this.sendTransaction(domain, transaction);
} catch (error: any) {
this.logger.error(`sendEvent failed: ${error?.message}`, error?.stack);
this.logger.error({ msg: 'sendEvent failed', err: error });
throw error;
}
}
Expand All @@ -154,7 +151,7 @@ export class FederationService {
const uri = FederationEndpoints.getEvent(eventId);
return await this.requestService.get<Pdu>(domain, uri);
} catch (error: any) {
this.logger.error(`getEvent failed: ${error?.message}`, error?.stack);
this.logger.error({ msg: 'getEvent failed', err: error });
throw error;
}
}
Expand All @@ -173,7 +170,7 @@ export class FederationService {

return await this.requestService.get<EventBase>(domain, uri, queryParams);
} catch (error: any) {
this.logger.error(`getState failed: ${error?.message}`, error?.stack);
this.logger.error({ msg: 'getState failed', err: error });
throw error;
}
}
Expand All @@ -186,7 +183,7 @@ export class FederationService {
const uri = FederationEndpoints.getStateIds(roomId);
return await this.requestService.get<EventBase[]>(domain, uri);
} catch (error: any) {
this.logger.error(`getStateIds failed: ${error?.message}`, error?.stack);
this.logger.error({ msg: 'getStateIds failed', err: error });
throw error;
}
}
Expand All @@ -201,7 +198,7 @@ export class FederationService {
FederationEndpoints.version,
);
} catch (error: any) {
this.logger.error(`getVersion failed: ${error?.message}`, error?.stack);
this.logger.error({ msg: 'getVersion failed', err: error });
throw error;
}
}
Expand All @@ -214,7 +211,7 @@ export class FederationService {
);

if (!inviteEvent.stateKey) {
this.logger.debug(inviteEvent.event, 'invalid state_key');
this.logger.debug({ msg: 'invalid state_key', event: inviteEvent.event });
throw new Error(
'failed to send invite request, invite has invalid state_key',
);
Expand Down Expand Up @@ -264,10 +261,10 @@ export class FederationService {
edus: [],
};

this.logger.info(
{ transaction: txn },
`Sending event ${event.eventId} to server: ${server}`,
);
this.logger.info({
transaction: txn,
msg: `Sending event ${event.eventId} to server: ${server}`,
});

try {
await this.sendTransaction(server, txn);
Expand Down
100 changes: 48 additions & 52 deletions packages/federation-sdk/src/services/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ export class RoomService {

try {
await this.roomRepository.upsert(roomId, state);
logger.info(`Successfully upserted room ${roomId}`);
logger.info({ msg: 'Successfully upserted room', roomId });
} catch (error) {
logger.error(`Failed to upsert room ${roomId}: ${error}`);
logger.error({ msg: 'Failed to upsert room', roomId, err: error });
throw error;
}
}
Expand Down Expand Up @@ -909,13 +909,11 @@ export class RoomService {
const persistEvent = async (event: Readonly<PersistentEventBase>) => {
if (!persisted.has(event.eventId) && event.isCreateEvent()) {
// persist as normal, m.room.create :)
logger.info(
`Persisting create event ${event.eventId}, ${JSON.stringify(
event.event,
null,
2,
)}`,
);
logger.info({
msg: 'Persisting create event',
eventId: event.eventId,
event: event.event,
});

const eventToPersist = copyEvent(event);

Expand All @@ -930,26 +928,23 @@ export class RoomService {
const authEvent = eventMap.get(authEventId as string);
if (!authEvent) {
for (const stateEvent of eventMap.keys()) {
console.log(
`${stateEvent} -> ${JSON.stringify(
eventMap.get(stateEvent)?.event,
null,
2,
)}`,
);
// TODO is this just suppose to log things?
logger.info({
msg: 'Auth event not found in event map',
stateEvent,
event: eventMap.get(stateEvent)?.event,
});
}
throw new Error(`Auth event ${authEventId} not found`);
}

if (!persisted.has(authEventId as string)) {
// persist all the auth events of this authEvent
logger.info(
`Persisting auth event ${authEventId} because not persisted already, ${JSON.stringify(
authEvent.event,
null,
2,
)}`,
);
logger.info({
msg: 'Persisting auth event because not persisted already',
authEventId,
event: authEvent.event,
});

// recursively persist this and all it's auth events
await persistEvent(authEvent); // pl
Expand All @@ -961,11 +956,11 @@ export class RoomService {
// ^^ all auth events of this event have been persisted

// persist as normal
logger.info(
`Persisting state event after auth events have been persisted, ${
event.eventId
}, ${JSON.stringify(event.event, null, 2)}`,
);
logger.info({
msg: 'Persisting state event after auth events have been persisted',
eventId: event.eventId,
event: event.event,
});

const eventToPersist = copyEvent(event);

Expand All @@ -979,13 +974,11 @@ export class RoomService {
continue;
}

logger.info(
`Persisting state event ${stateEvent.eventId}, ${JSON.stringify(
stateEvent.event,
null,
2,
)}`,
);
logger.info({
msg: 'Persisting state event',
eventId: stateEvent.eventId,
event: stateEvent.event,
});
await persistEvent(stateEvent);
}

Expand All @@ -996,22 +989,18 @@ export class RoomService {
makeJoinResponse.room_version,
);

logger.info(
`Persisting join event ${joinEventFinal.eventId}, ${JSON.stringify(
joinEventFinal.event,
null,
2,
)}`,
);
logger.info({
msg: 'Persisting join event',
eventId: joinEventFinal.eventId,
event: joinEventFinal.event,
});

const state = await stateService.getFullRoomState(roomId);

logger.info(
`State before join event has been persisted, ${state
.keys()
.toArray()
.join(', ')}`,
);
logger.info({
msg: 'State before join event has been persisted',
state: state.keys().toArray().join(', '),
});

// try to persist the join event now, should succeed with state in place
await this.eventService.processIncomingPDUs(
Expand Down Expand Up @@ -1137,7 +1126,11 @@ export class RoomService {
this.eventRepository.findTombstoneEventsByRoomId(roomId);
return (await tombstoneEvents.toArray()).length > 0;
} catch (error) {
logger.error(`Error checking if room ${roomId} is tombstoned: ${error}`);
logger.error({
msg: 'Error checking if room is tombstoned',
roomId,
err: error,
});
return false;
}
}
Expand Down Expand Up @@ -1433,9 +1426,12 @@ export class RoomService {

return null;
} catch (error) {
logger.error(
`Error finding existing DM room between ${userId1} and ${userId2}: ${error}`,
);
logger.error({
msg: 'Error finding existing DM room between users',
userId1,
userId2,
err: error,
});
return null;
}
}
Expand Down