Skip to content

Commit

Permalink
log potential errors with sync, avoid stopping sync completely
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Oct 21, 2024
1 parent 5120f6f commit b257313
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/agent/src/sync-engine-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,12 @@ export class SyncEngineLevel implements SyncEngine {

clearInterval(this._syncIntervalId);
this._syncIntervalId = undefined;
await this.sync();

try {
await this.sync();
} catch (error) {
console.error('SyncEngineLevel: Error during sync operation', error);
}

Check warning on line 346 in packages/agent/src/sync-engine-level.ts

View check run for this annotation

Codecov / codecov/patch

packages/agent/src/sync-engine-level.ts#L345-L346

Added lines #L345 - L346 were not covered by tests

if (!this._syncIntervalId) {
this._syncIntervalId = setInterval(intervalSync, intervalMilliseconds);
Expand Down Expand Up @@ -405,7 +410,7 @@ export class SyncEngineLevel implements SyncEngine {
syncDirection: SyncDirection,
syncPeerState: SyncState[]
}) {
for (let syncState of syncPeerState) {
const enqueueOps = await Promise.allSettled(syncPeerState.map(async (syncState) => {
// Get the event log from the remote DWN if pull sync, or local DWN if push sync.
const eventLog = await this.getDwnEventLog({
did : syncState.did,
Expand Down Expand Up @@ -435,7 +440,15 @@ export class SyncEngineLevel implements SyncEngine {
: this.getPushQueue();
await syncQueue.batch(syncOperations as any);
}
}
}));

// log any errors that occurred during the enqueuing process
enqueueOps.forEach((result, index) => {
if (result.status === 'rejected') {
const peerState = syncPeerState[index];
console.error(`SyncEngineLevel: Error enqueuing sync operation for peerState: ${JSON.stringify(peerState)}`, result.reason);
}

Check warning on line 450 in packages/agent/src/sync-engine-level.ts

View check run for this annotation

Codecov / codecov/patch

packages/agent/src/sync-engine-level.ts#L448-L450

Added lines #L448 - L450 were not covered by tests
});
}

private static generateSyncMessageParamsKey({ did, delegateDid, dwnUrl, protocol, watermark, messageCid }:SyncMessageParams): string {
Expand Down

0 comments on commit b257313

Please sign in to comment.