Skip to content

Commit

Permalink
Fix error propagation (#84)
Browse files Browse the repository at this point in the history
* fix propagation of errors via sendTo

* one more case
  • Loading branch information
foxriver76 authored Aug 29, 2024
1 parent 6766ebd commit f85d38b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/matter/ControllerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export interface ControllerCreateOptions {

interface AddDeviceResult {
result: boolean;
error?: Error;
/** The error message */
error?: string;
nodeId?: string;
}

Expand Down Expand Up @@ -625,7 +626,7 @@ class Controller implements GeneralNode {
device: CommissionableDevice,
): Promise<AddDeviceResult> {
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,
Expand Down Expand Up @@ -700,17 +701,17 @@ 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 };
}
}

async completeCommissioningForNode(nodeId: NodeId, discoveryData?: DiscoveryData): Promise<AddDeviceResult> {
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.`,
};
}

Expand Down

0 comments on commit f85d38b

Please sign in to comment.