From 70fa746458b7a49a00628f118ccfd8f1bef886a3 Mon Sep 17 00:00:00 2001 From: Marcin Gordel Date: Thu, 11 Jul 2024 14:50:54 +0200 Subject: [PATCH 1/3] fix(resource-rental): fixed error handling when creating an exe-unit --- src/resource-rental/resource-rental.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/resource-rental/resource-rental.ts b/src/resource-rental/resource-rental.ts index 8933cdac7..6059cd1e3 100644 --- a/src/resource-rental/resource-rental.ts +++ b/src/resource-rental/resource-rental.ts @@ -53,7 +53,10 @@ export class ResourceRental { ) { this.networkNode = this.resourceRentalOptions?.networkNode; - this.createExeUnit(this.abortController.signal); + this.createExeUnit(this.abortController.signal).catch((error) => { + this.events.emit("error", error); + this.logger.error(`Failed to create exe-unit. ${error}`, { agreementId: this.agreement.id }); + }); // TODO: Listen to agreement events to know when it goes down due to provider closing it! } @@ -181,15 +184,9 @@ export class ResourceRental { }); this.events.emit("exeUnitCreated", activity); return this.currentExeUnit; - })() - .catch((error) => { - this.events.emit("error", error); - this.logger.error(`Failed to create exe-unit. ${error}`, { agreementId: this.agreement.id }); - throw error; - }) - .finally(() => { - this.exeUnitPromise = undefined; - }); + })().finally(() => { + this.exeUnitPromise = undefined; + }); } return this.exeUnitPromise; } From 6ac6f8ec2915f25fa67c8fb00f1243e50c6e0e4e Mon Sep 17 00:00:00 2001 From: Marcin Gordel Date: Thu, 11 Jul 2024 15:02:00 +0200 Subject: [PATCH 2/3] refactor: moved logging and event emitting to first catch block --- src/resource-rental/resource-rental.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/resource-rental/resource-rental.ts b/src/resource-rental/resource-rental.ts index 6059cd1e3..0cad4ccdf 100644 --- a/src/resource-rental/resource-rental.ts +++ b/src/resource-rental/resource-rental.ts @@ -53,10 +53,7 @@ export class ResourceRental { ) { this.networkNode = this.resourceRentalOptions?.networkNode; - this.createExeUnit(this.abortController.signal).catch((error) => { - this.events.emit("error", error); - this.logger.error(`Failed to create exe-unit. ${error}`, { agreementId: this.agreement.id }); - }); + this.createExeUnit(this.abortController.signal).catch(() => null); // TODO: Listen to agreement events to know when it goes down due to provider closing it! } @@ -184,9 +181,15 @@ export class ResourceRental { }); this.events.emit("exeUnitCreated", activity); return this.currentExeUnit; - })().finally(() => { - this.exeUnitPromise = undefined; - }); + })() + .catch((error) => { + this.events.emit("error", error); + this.logger.error(`Failed to create exe-unit. ${error}`, { agreementId: this.agreement.id }); + throw error; + }) + .finally(() => { + this.exeUnitPromise = undefined; + }); } return this.exeUnitPromise; } From cb16e9d3424794a97cd5d8cb97a2d3ce28872a4c Mon Sep 17 00:00:00 2001 From: Marcin Gordel Date: Mon, 15 Jul 2024 15:55:25 +0200 Subject: [PATCH 3/3] refactor: added debug logging to error handling --- src/resource-rental/resource-rental.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/resource-rental/resource-rental.ts b/src/resource-rental/resource-rental.ts index 0cad4ccdf..9dfb99bc9 100644 --- a/src/resource-rental/resource-rental.ts +++ b/src/resource-rental/resource-rental.ts @@ -53,7 +53,9 @@ export class ResourceRental { ) { this.networkNode = this.resourceRentalOptions?.networkNode; - this.createExeUnit(this.abortController.signal).catch(() => null); + this.createExeUnit(this.abortController.signal).catch((error) => + this.logger.debug(`Failed to automatically create the exe unit during resource rental initialization`, { error }), + ); // TODO: Listen to agreement events to know when it goes down due to provider closing it! }