From f85d38b902de0f4619b9a2a657a7c2e2242c5f08 Mon Sep 17 00:00:00 2001 From: Max Hauser Date: Thu, 29 Aug 2024 11:21:23 +0200 Subject: [PATCH] Fix error propagation (#84) * fix propagation of errors via sendTo * one more case --- src/matter/ControllerNode.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/matter/ControllerNode.ts b/src/matter/ControllerNode.ts index dafa942c..900dff57 100644 --- a/src/matter/ControllerNode.ts +++ b/src/matter/ControllerNode.ts @@ -37,7 +37,8 @@ export interface ControllerCreateOptions { interface AddDeviceResult { result: boolean; - error?: Error; + /** The error message */ + error?: string; nodeId?: string; } @@ -625,7 +626,7 @@ class Controller implements GeneralNode { device: CommissionableDevice, ): Promise { if (!this.#commissioningController) { - return { error: new Error('Controller is not activated.'), result: false }; + return { error: 'Controller is not activated.', result: false }; } const commissioningOptions: CommissioningOptions = { regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor, @@ -700,9 +701,9 @@ class Controller implements GeneralNode { await this.registerCommissionedNode(nodeId); return { result: true, nodeId: nodeId.toString() }; - } catch (error) { - this.#adapter.log.info(`Commissioning failed: ${error.stack}`); - return { error, result: false }; + } catch (e) { + this.#adapter.log.info(`Commissioning failed: ${e.stack}`); + return { error: e.message, result: false }; } } @@ -710,7 +711,7 @@ class Controller implements GeneralNode { if (!this.#commissioningController) { return { result: false, - error: new Error(`Can not register NodeId "${nodeId}" because controller not initialized.`), + error: `Can not register NodeId "${nodeId}" because controller not initialized.`, }; }