From a69ee056ca4b3e2852b6f5f55dba66f1b04913e5 Mon Sep 17 00:00:00 2001 From: hoangquocvietuet <hoangquocvietuet@gmail.com> Date: Tue, 21 Jan 2025 08:58:58 +0700 Subject: [PATCH 1/4] fix: add apply operation error handler --- packages/object/src/index.ts | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/object/src/index.ts b/packages/object/src/index.ts index 85376f66f..ec862a863 100644 --- a/packages/object/src/index.ts +++ b/packages/object/src/index.ts @@ -177,7 +177,7 @@ export class DRPObject implements IDRPObject { }; } - callFn( + private callFn( fn: string, // biome-ignore lint: value can't be unknown because of protobuf args: any, @@ -191,7 +191,12 @@ export class DRPObject implements IDRPObject { preOperationDRP = this._computeDRP(this.hashGraph.getFrontier()); } const drp = cloneDeep(preOperationDRP); - this._applyOperation(drp, { opType: fn, value: args, drpType }); + try { + this._applyOperation(drp, { opType: fn, value: args, drpType }); + } catch (e) { + log.error(`Object ${this.id} failed to apply operation: ${e} in callFn ${fn}`); + return; + } let stateChanged = false; for (const key of Object.keys(preOperationDRP)) { @@ -252,7 +257,13 @@ export class DRPObject implements IDRPObject { vertex.timestamp, vertex.signature, ); - this._applyOperation(drp, vertex.operation); + try { + this._applyOperation(drp, vertex.operation); + } catch (e) { + log.error(`Object ${this.id} failed to apply operation: ${e} in merge`); + missing.push(vertex.hash); + continue; + } this._setACLState(vertex, preComputeLca); this._setDRPState(vertex, preComputeLca, this._getDRPState(drp)); @@ -266,7 +277,13 @@ export class DRPObject implements IDRPObject { vertex.timestamp, vertex.signature, ); - this._applyOperation(acl, vertex.operation); + try { + this._applyOperation(acl, vertex.operation); + } catch (e) { + log.error(`Object ${this.id} failed to apply operation: ${e} in merge`); + missing.push(vertex.hash); + continue; + } this._setACLState(vertex, preComputeLca, this._getDRPState(acl)); this._setDRPState(vertex, preComputeLca); @@ -334,7 +351,11 @@ export class DRPObject implements IDRPObject { throw new Error(`${opType} is not a function`); } - target[methodName](...value); + try { + target[methodName](...value); + } catch (e) { + throw new Error(`Error while applying operation ${opType}: ${e}`); + } } // compute the DRP based on all dependencies of the current vertex using partial linearization From 5c5bac427734ea31d674492bd8d6452b6c489ec4 Mon Sep 17 00:00:00 2001 From: hoangquocvietuet <hoangquocvietuet@gmail.com> Date: Tue, 21 Jan 2025 09:00:17 +0700 Subject: [PATCH 2/4] fix biome --- packages/object/src/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/object/src/index.ts b/packages/object/src/index.ts index ec862a863..20ba21b08 100644 --- a/packages/object/src/index.ts +++ b/packages/object/src/index.ts @@ -194,7 +194,9 @@ export class DRPObject implements IDRPObject { try { this._applyOperation(drp, { opType: fn, value: args, drpType }); } catch (e) { - log.error(`Object ${this.id} failed to apply operation: ${e} in callFn ${fn}`); + log.error( + `Object ${this.id} failed to apply operation: ${e} in callFn ${fn}`, + ); return; } @@ -260,7 +262,9 @@ export class DRPObject implements IDRPObject { try { this._applyOperation(drp, vertex.operation); } catch (e) { - log.error(`Object ${this.id} failed to apply operation: ${e} in merge`); + log.error( + `Object ${this.id} failed to apply operation: ${e} in merge`, + ); missing.push(vertex.hash); continue; } @@ -280,7 +284,9 @@ export class DRPObject implements IDRPObject { try { this._applyOperation(acl, vertex.operation); } catch (e) { - log.error(`Object ${this.id} failed to apply operation: ${e} in merge`); + log.error( + `Object ${this.id} failed to apply operation: ${e} in merge`, + ); missing.push(vertex.hash); continue; } From 8cfbba4343961e3307b57176b313d733cbbba8f1 Mon Sep 17 00:00:00 2001 From: hoangquocvietuet <hoangquocvietuet@gmail.com> Date: Tue, 21 Jan 2025 12:37:58 +0700 Subject: [PATCH 3/4] remove try catch inside --- packages/object/src/index.ts | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/packages/object/src/index.ts b/packages/object/src/index.ts index 20ba21b08..f3f3d9813 100644 --- a/packages/object/src/index.ts +++ b/packages/object/src/index.ts @@ -259,15 +259,7 @@ export class DRPObject implements IDRPObject { vertex.timestamp, vertex.signature, ); - try { - this._applyOperation(drp, vertex.operation); - } catch (e) { - log.error( - `Object ${this.id} failed to apply operation: ${e} in merge`, - ); - missing.push(vertex.hash); - continue; - } + this._applyOperation(drp, vertex.operation); this._setACLState(vertex, preComputeLca); this._setDRPState(vertex, preComputeLca, this._getDRPState(drp)); @@ -281,15 +273,7 @@ export class DRPObject implements IDRPObject { vertex.timestamp, vertex.signature, ); - try { - this._applyOperation(acl, vertex.operation); - } catch (e) { - log.error( - `Object ${this.id} failed to apply operation: ${e} in merge`, - ); - missing.push(vertex.hash); - continue; - } + this._applyOperation(acl, vertex.operation); this._setACLState(vertex, preComputeLca, this._getDRPState(acl)); this._setDRPState(vertex, preComputeLca); From 971940e7e6505252598dc0af9d41c89030883e73 Mon Sep 17 00:00:00 2001 From: hoangquocvietuet <hoangquocvietuet@gmail.com> Date: Tue, 21 Jan 2025 16:50:40 +0700 Subject: [PATCH 4/4] resolve comment --- packages/object/src/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/object/src/index.ts b/packages/object/src/index.ts index f3f3d9813..1bfed3c5a 100644 --- a/packages/object/src/index.ts +++ b/packages/object/src/index.ts @@ -194,9 +194,7 @@ export class DRPObject implements IDRPObject { try { this._applyOperation(drp, { opType: fn, value: args, drpType }); } catch (e) { - log.error( - `Object ${this.id} failed to apply operation: ${e} in callFn ${fn}`, - ); + log.error(`::drpObject::callFn: ${e}`); return; }