homebridge 2.0.0-alpha.4 → 2.0.0-alpha.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/homebridge.js +22 -0
- package/dist/api.d.ts +210 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +140 -0
- package/dist/api.js.map +1 -0
- package/dist/bridgeService.d.ts +122 -0
- package/dist/bridgeService.d.ts.map +1 -0
- package/dist/bridgeService.js +396 -0
- package/dist/bridgeService.js.map +1 -0
- package/dist/childBridgeFork.d.ts +38 -0
- package/dist/childBridgeFork.d.ts.map +1 -0
- package/dist/childBridgeFork.js +241 -2
- package/dist/childBridgeFork.js.map +1 -7
- package/dist/childBridgeService.d.ts +204 -0
- package/dist/childBridgeService.d.ts.map +1 -0
- package/dist/childBridgeService.js +452 -0
- package/dist/childBridgeService.js.map +1 -0
- package/dist/childMatterBridgeFork.d.ts +108 -0
- package/dist/childMatterBridgeFork.d.ts.map +1 -0
- package/dist/childMatterBridgeFork.js +330 -0
- package/dist/childMatterBridgeFork.js.map +1 -0
- package/dist/childMatterBridgeService.d.ts +166 -0
- package/dist/childMatterBridgeService.d.ts.map +1 -0
- package/dist/childMatterBridgeService.js +623 -0
- package/dist/childMatterBridgeService.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +90 -2
- package/dist/cli.js.map +1 -7
- package/dist/externalPortService.d.ts +33 -0
- package/dist/externalPortService.d.ts.map +1 -0
- package/dist/externalPortService.js +59 -0
- package/dist/externalPortService.js.map +1 -0
- package/dist/index.d.ts +90 -1099
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -7
- package/dist/ipcService.d.ts +46 -0
- package/dist/ipcService.d.ts.map +1 -0
- package/dist/ipcService.js +62 -0
- package/dist/ipcService.js.map +1 -0
- package/dist/logger.d.ts +78 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +138 -0
- package/dist/logger.js.map +1 -0
- package/dist/matter/index.d.ts +13 -0
- package/dist/matter/index.d.ts.map +1 -0
- package/dist/matter/index.js +12 -0
- package/dist/matter/index.js.map +1 -0
- package/dist/matter/matterBridge.d.ts +64 -0
- package/dist/matter/matterBridge.d.ts.map +1 -0
- package/dist/matter/matterBridge.js +154 -0
- package/dist/matter/matterBridge.js.map +1 -0
- package/dist/matter/matterConfigValidator.d.ts +27 -0
- package/dist/matter/matterConfigValidator.d.ts.map +1 -0
- package/dist/matter/matterConfigValidator.js +162 -0
- package/dist/matter/matterConfigValidator.js.map +1 -0
- package/dist/matter/matterDevice.d.ts +107 -0
- package/dist/matter/matterDevice.d.ts.map +1 -0
- package/dist/matter/matterDevice.js +913 -0
- package/dist/matter/matterDevice.js.map +1 -0
- package/dist/matter/matterDiagnostics.d.ts +121 -0
- package/dist/matter/matterDiagnostics.d.ts.map +1 -0
- package/dist/matter/matterDiagnostics.js +323 -0
- package/dist/matter/matterDiagnostics.js.map +1 -0
- package/dist/matter/matterErrorHandler.d.ts +113 -0
- package/dist/matter/matterErrorHandler.d.ts.map +1 -0
- package/dist/matter/matterErrorHandler.js +482 -0
- package/dist/matter/matterErrorHandler.js.map +1 -0
- package/dist/matter/matterNetworkMonitor.d.ts +65 -0
- package/dist/matter/matterNetworkMonitor.d.ts.map +1 -0
- package/dist/matter/matterNetworkMonitor.js +227 -0
- package/dist/matter/matterNetworkMonitor.js.map +1 -0
- package/dist/matter/matterServer.d.ts +110 -0
- package/dist/matter/matterServer.d.ts.map +1 -0
- package/dist/matter/matterServer.js +584 -0
- package/dist/matter/matterServer.js.map +1 -0
- package/dist/matter/matterSharedTypes.d.ts +167 -0
- package/dist/matter/matterSharedTypes.d.ts.map +1 -0
- package/dist/matter/matterSharedTypes.js +55 -0
- package/dist/matter/matterSharedTypes.js.map +1 -0
- package/dist/matter/matterTypes.d.ts +35 -0
- package/dist/matter/matterTypes.d.ts.map +1 -0
- package/dist/matter/matterTypes.js +278 -0
- package/dist/matter/matterTypes.js.map +1 -0
- package/dist/matter/portAllocator.d.ts +85 -0
- package/dist/matter/portAllocator.d.ts.map +1 -0
- package/dist/matter/portAllocator.js +296 -0
- package/dist/matter/portAllocator.js.map +1 -0
- package/dist/platformAccessory.d.ts +56 -0
- package/dist/platformAccessory.d.ts.map +1 -0
- package/dist/platformAccessory.js +105 -0
- package/dist/platformAccessory.js.map +1 -0
- package/dist/plugin.d.ts +30 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +182 -0
- package/dist/plugin.js.map +1 -0
- package/dist/pluginManager.d.ts +77 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +375 -0
- package/dist/pluginManager.js.map +1 -0
- package/dist/server.d.ts +67 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +799 -0
- package/dist/server.js.map +1 -0
- package/dist/storageService.d.ts +13 -0
- package/dist/storageService.d.ts.map +1 -0
- package/dist/storageService.js +41 -0
- package/dist/storageService.js.map +1 -0
- package/dist/user.d.ts +13 -0
- package/dist/user.d.ts.map +1 -0
- package/dist/user.js +29 -0
- package/dist/user.js.map +1 -0
- package/dist/util/mac.d.ts +5 -0
- package/dist/util/mac.d.ts.map +1 -0
- package/dist/util/mac.js +14 -0
- package/dist/util/mac.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +16 -0
- package/dist/version.js.map +1 -0
- package/package.json +31 -34
- package/bin/homebridge +0 -19
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matter Error Handler
|
|
3
|
+
*
|
|
4
|
+
* Centralized error handling and recovery for Matter.js integration
|
|
5
|
+
* with circuit breaker pattern and contextual recovery
|
|
6
|
+
*/
|
|
7
|
+
import { Logger } from '../logger.js';
|
|
8
|
+
const log = Logger.withPrefix('Matter');
|
|
9
|
+
export var MatterErrorType;
|
|
10
|
+
(function (MatterErrorType) {
|
|
11
|
+
MatterErrorType["INITIALIZATION"] = "INITIALIZATION";
|
|
12
|
+
MatterErrorType["NETWORK"] = "NETWORK";
|
|
13
|
+
MatterErrorType["COMMISSIONING"] = "COMMISSIONING";
|
|
14
|
+
MatterErrorType["DEVICE_SYNC"] = "DEVICE_SYNC";
|
|
15
|
+
MatterErrorType["SERVER"] = "SERVER";
|
|
16
|
+
MatterErrorType["STORAGE"] = "STORAGE";
|
|
17
|
+
MatterErrorType["CONFIGURATION"] = "CONFIGURATION";
|
|
18
|
+
MatterErrorType["UNKNOWN"] = "UNKNOWN";
|
|
19
|
+
})(MatterErrorType || (MatterErrorType = {}));
|
|
20
|
+
/**
|
|
21
|
+
* Circuit breaker states
|
|
22
|
+
*/
|
|
23
|
+
var CircuitState;
|
|
24
|
+
(function (CircuitState) {
|
|
25
|
+
CircuitState["CLOSED"] = "CLOSED";
|
|
26
|
+
CircuitState["OPEN"] = "OPEN";
|
|
27
|
+
CircuitState["HALF_OPEN"] = "HALF_OPEN";
|
|
28
|
+
})(CircuitState || (CircuitState = {}));
|
|
29
|
+
/**
|
|
30
|
+
* Circuit breaker for error recovery
|
|
31
|
+
*/
|
|
32
|
+
class CircuitBreaker {
|
|
33
|
+
threshold;
|
|
34
|
+
timeout;
|
|
35
|
+
successThreshold;
|
|
36
|
+
state = CircuitState.CLOSED;
|
|
37
|
+
failureCount = 0;
|
|
38
|
+
successCount = 0;
|
|
39
|
+
lastFailureTime = 0;
|
|
40
|
+
nextAttemptTime = 0;
|
|
41
|
+
constructor(threshold = 5, timeout = 60000, // 1 minute
|
|
42
|
+
successThreshold = 3) {
|
|
43
|
+
this.threshold = threshold;
|
|
44
|
+
this.timeout = timeout;
|
|
45
|
+
this.successThreshold = successThreshold;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if operation should be allowed
|
|
49
|
+
*/
|
|
50
|
+
canAttempt() {
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
switch (this.state) {
|
|
53
|
+
case CircuitState.CLOSED:
|
|
54
|
+
return true;
|
|
55
|
+
case CircuitState.OPEN:
|
|
56
|
+
if (now >= this.nextAttemptTime) {
|
|
57
|
+
this.state = CircuitState.HALF_OPEN;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
case CircuitState.HALF_OPEN:
|
|
62
|
+
return true;
|
|
63
|
+
default:
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Record success
|
|
69
|
+
*/
|
|
70
|
+
recordSuccess() {
|
|
71
|
+
this.failureCount = 0;
|
|
72
|
+
if (this.state === CircuitState.HALF_OPEN) {
|
|
73
|
+
this.successCount++;
|
|
74
|
+
if (this.successCount >= this.successThreshold) {
|
|
75
|
+
this.state = CircuitState.CLOSED;
|
|
76
|
+
this.successCount = 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Record failure
|
|
82
|
+
*/
|
|
83
|
+
recordFailure() {
|
|
84
|
+
this.failureCount++;
|
|
85
|
+
this.lastFailureTime = Date.now();
|
|
86
|
+
this.successCount = 0;
|
|
87
|
+
if (this.state === CircuitState.HALF_OPEN) {
|
|
88
|
+
this.state = CircuitState.OPEN;
|
|
89
|
+
this.nextAttemptTime = Date.now() + this.timeout;
|
|
90
|
+
}
|
|
91
|
+
else if (this.failureCount >= this.threshold) {
|
|
92
|
+
this.state = CircuitState.OPEN;
|
|
93
|
+
this.nextAttemptTime = Date.now() + this.timeout;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get current state
|
|
98
|
+
*/
|
|
99
|
+
getState() {
|
|
100
|
+
return this.state;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Reset the circuit breaker
|
|
104
|
+
*/
|
|
105
|
+
reset() {
|
|
106
|
+
this.state = CircuitState.CLOSED;
|
|
107
|
+
this.failureCount = 0;
|
|
108
|
+
this.successCount = 0;
|
|
109
|
+
this.lastFailureTime = 0;
|
|
110
|
+
this.nextAttemptTime = 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export class MatterErrorHandler {
|
|
114
|
+
static instance;
|
|
115
|
+
errorCount = new Map();
|
|
116
|
+
lastErrors = new Map();
|
|
117
|
+
recoveryCallbacks = new Map();
|
|
118
|
+
circuitBreakers = new Map();
|
|
119
|
+
recoveryContexts = new Map();
|
|
120
|
+
maxRetries = 3;
|
|
121
|
+
retryDelays = [1000, 5000, 10000]; // Exponential backoff
|
|
122
|
+
MAX_RECOVERY_ATTEMPTS = 5;
|
|
123
|
+
contextualRetryLimits = new Map([
|
|
124
|
+
[MatterErrorType.NETWORK, 5],
|
|
125
|
+
[MatterErrorType.DEVICE_SYNC, 3],
|
|
126
|
+
[MatterErrorType.STORAGE, 2],
|
|
127
|
+
[MatterErrorType.SERVER, 1],
|
|
128
|
+
]);
|
|
129
|
+
constructor() { }
|
|
130
|
+
static getInstance() {
|
|
131
|
+
if (!MatterErrorHandler.instance) {
|
|
132
|
+
MatterErrorHandler.instance = new MatterErrorHandler();
|
|
133
|
+
}
|
|
134
|
+
return MatterErrorHandler.instance;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Handle a Matter error with context-aware recovery
|
|
138
|
+
*/
|
|
139
|
+
async handleError(error, context) {
|
|
140
|
+
const matterError = this.categorizeError(error, context);
|
|
141
|
+
// Log the error with appropriate level
|
|
142
|
+
this.logError(matterError);
|
|
143
|
+
// Track error occurrence
|
|
144
|
+
this.trackError(matterError);
|
|
145
|
+
// Check circuit breaker before attempting recovery
|
|
146
|
+
const circuitBreaker = this.getOrCreateCircuitBreaker(matterError.type);
|
|
147
|
+
if (matterError.recoverable && circuitBreaker.canAttempt()) {
|
|
148
|
+
// Check if we should attempt recovery based on context
|
|
149
|
+
if (this.shouldAttemptRecovery(matterError)) {
|
|
150
|
+
this.attemptContextualRecovery(matterError, circuitBreaker).catch((err) => {
|
|
151
|
+
log.debug(`Recovery attempt failed for ${matterError.type}:`, err);
|
|
152
|
+
circuitBreaker.recordFailure();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (!circuitBreaker.canAttempt()) {
|
|
157
|
+
log.debug(`Circuit breaker OPEN for ${matterError.type}, skipping recovery`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Categorize error into Matter error types
|
|
162
|
+
*/
|
|
163
|
+
categorizeError(error, context) {
|
|
164
|
+
if ('type' in error) {
|
|
165
|
+
return error;
|
|
166
|
+
}
|
|
167
|
+
const matterError = error;
|
|
168
|
+
matterError.timestamp = new Date();
|
|
169
|
+
// Categorize based on error message and context
|
|
170
|
+
if (error.message.includes('EADDRINUSE')) {
|
|
171
|
+
matterError.type = MatterErrorType.NETWORK;
|
|
172
|
+
matterError.code = 'PORT_IN_USE';
|
|
173
|
+
matterError.recoverable = false;
|
|
174
|
+
}
|
|
175
|
+
else if (error.message.includes('ECONNREFUSED') || error.message.includes('ETIMEDOUT')) {
|
|
176
|
+
matterError.type = MatterErrorType.NETWORK;
|
|
177
|
+
matterError.code = 'CONNECTION_FAILED';
|
|
178
|
+
matterError.recoverable = true;
|
|
179
|
+
}
|
|
180
|
+
else if (error.message.includes('commissioning') || error.message.includes('pairing')) {
|
|
181
|
+
matterError.type = MatterErrorType.COMMISSIONING;
|
|
182
|
+
matterError.recoverable = false;
|
|
183
|
+
}
|
|
184
|
+
else if (error.message.includes('storage') || error.message.includes('ENOENT')) {
|
|
185
|
+
matterError.type = MatterErrorType.STORAGE;
|
|
186
|
+
matterError.recoverable = true;
|
|
187
|
+
}
|
|
188
|
+
else if (error.message.includes('config') || error.message.includes('invalid')) {
|
|
189
|
+
matterError.type = MatterErrorType.CONFIGURATION;
|
|
190
|
+
matterError.recoverable = false;
|
|
191
|
+
}
|
|
192
|
+
else if (context?.includes('sync')) {
|
|
193
|
+
matterError.type = MatterErrorType.DEVICE_SYNC;
|
|
194
|
+
matterError.recoverable = true;
|
|
195
|
+
}
|
|
196
|
+
else if (context?.includes('server')) {
|
|
197
|
+
matterError.type = MatterErrorType.SERVER;
|
|
198
|
+
matterError.recoverable = true;
|
|
199
|
+
}
|
|
200
|
+
else if (context?.includes('init')) {
|
|
201
|
+
matterError.type = MatterErrorType.INITIALIZATION;
|
|
202
|
+
matterError.recoverable = true;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
matterError.type = MatterErrorType.UNKNOWN;
|
|
206
|
+
matterError.recoverable = false;
|
|
207
|
+
}
|
|
208
|
+
return matterError;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Log error with appropriate severity
|
|
212
|
+
*/
|
|
213
|
+
logError(error) {
|
|
214
|
+
const errorCount = this.errorCount.get(error.type) || 0;
|
|
215
|
+
switch (error.type) {
|
|
216
|
+
case MatterErrorType.NETWORK:
|
|
217
|
+
if (error.code === 'PORT_IN_USE') {
|
|
218
|
+
log.error('Matter port is already in use. Please configure a different port.');
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
log.warn(`Matter network error: ${error.message}`);
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
case MatterErrorType.COMMISSIONING:
|
|
225
|
+
log.info(`Matter commissioning issue: ${error.message}`);
|
|
226
|
+
break;
|
|
227
|
+
case MatterErrorType.DEVICE_SYNC:
|
|
228
|
+
if (errorCount < 3) {
|
|
229
|
+
log.debug(`Device sync error: ${error.message}`);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
log.warn(`Repeated device sync errors: ${error.message}`);
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
case MatterErrorType.SERVER:
|
|
236
|
+
log.error(`Matter server error: ${error.message}`);
|
|
237
|
+
break;
|
|
238
|
+
case MatterErrorType.STORAGE:
|
|
239
|
+
log.warn(`Matter storage error: ${error.message}`);
|
|
240
|
+
break;
|
|
241
|
+
case MatterErrorType.CONFIGURATION:
|
|
242
|
+
log.error(`Matter configuration error: ${error.message}`);
|
|
243
|
+
break;
|
|
244
|
+
case MatterErrorType.INITIALIZATION:
|
|
245
|
+
log.error(`Matter initialization error: ${error.message}`);
|
|
246
|
+
break;
|
|
247
|
+
default:
|
|
248
|
+
log.error(`Unknown Matter error: ${error.message}`);
|
|
249
|
+
}
|
|
250
|
+
// Log stack trace for non-recoverable errors
|
|
251
|
+
if (!error.recoverable && error.stack) {
|
|
252
|
+
log.debug('Stack trace:', error.stack);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Track error occurrences with bounds checking
|
|
257
|
+
*/
|
|
258
|
+
trackError(error) {
|
|
259
|
+
// Limit total error types tracked to prevent unbounded growth
|
|
260
|
+
const MAX_ERROR_TYPES = 50;
|
|
261
|
+
const MAX_ERRORS_PER_TYPE = 100;
|
|
262
|
+
if (!this.errorCount.has(error.type) && this.errorCount.size >= MAX_ERROR_TYPES) {
|
|
263
|
+
// Remove oldest error type
|
|
264
|
+
const firstKey = this.errorCount.keys().next().value;
|
|
265
|
+
if (firstKey) {
|
|
266
|
+
this.errorCount.delete(firstKey);
|
|
267
|
+
this.lastErrors.delete(firstKey);
|
|
268
|
+
this.recoveryContexts.delete(firstKey);
|
|
269
|
+
this.circuitBreakers.delete(firstKey);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const count = (this.errorCount.get(error.type) || 0) + 1;
|
|
273
|
+
// Cap error count per type
|
|
274
|
+
this.errorCount.set(error.type, Math.min(count, MAX_ERRORS_PER_TYPE));
|
|
275
|
+
this.lastErrors.set(error.type, error);
|
|
276
|
+
// Auto-cleanup old errors after 1 hour
|
|
277
|
+
setTimeout(() => {
|
|
278
|
+
const currentError = this.lastErrors.get(error.type);
|
|
279
|
+
if (currentError && currentError.timestamp === error.timestamp) {
|
|
280
|
+
this.clearErrors(error.type);
|
|
281
|
+
}
|
|
282
|
+
}, 3600000); // 1 hour
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Clear errors for a specific type
|
|
286
|
+
*/
|
|
287
|
+
clearErrors(errorType) {
|
|
288
|
+
this.errorCount.delete(errorType);
|
|
289
|
+
this.lastErrors.delete(errorType);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Attempt contextual recovery from error
|
|
293
|
+
*/
|
|
294
|
+
async attemptContextualRecovery(error, circuitBreaker) {
|
|
295
|
+
// Get or create recovery context
|
|
296
|
+
let context = this.recoveryContexts.get(error.type);
|
|
297
|
+
if (!context) {
|
|
298
|
+
context = {
|
|
299
|
+
errorType: error.type,
|
|
300
|
+
attemptCount: 0,
|
|
301
|
+
lastAttemptTime: 0,
|
|
302
|
+
backoffMultiplier: 1,
|
|
303
|
+
};
|
|
304
|
+
this.recoveryContexts.set(error.type, context);
|
|
305
|
+
}
|
|
306
|
+
context.attemptCount++;
|
|
307
|
+
context.lastAttemptTime = Date.now();
|
|
308
|
+
const delay = this.getContextualDelay(error.type, context.attemptCount - 1);
|
|
309
|
+
log.info(`Attempting recovery from ${error.type} error (attempt ${context.attemptCount}) in ${delay}ms`);
|
|
310
|
+
// Use global.setTimeout so it can be mocked in tests
|
|
311
|
+
await new Promise(resolve => globalThis.setTimeout(resolve, delay));
|
|
312
|
+
try {
|
|
313
|
+
const callbacks = this.recoveryCallbacks.get(error.type) || [];
|
|
314
|
+
let anySuccess = false;
|
|
315
|
+
for (const callback of callbacks) {
|
|
316
|
+
try {
|
|
317
|
+
await callback();
|
|
318
|
+
anySuccess = true;
|
|
319
|
+
}
|
|
320
|
+
catch (callbackError) {
|
|
321
|
+
log.debug(`Recovery callback failed for ${error.type}:`, callbackError);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (anySuccess) {
|
|
325
|
+
circuitBreaker.recordSuccess();
|
|
326
|
+
// Reset context on success
|
|
327
|
+
this.recoveryContexts.delete(error.type);
|
|
328
|
+
this.errorCount.set(error.type, 0);
|
|
329
|
+
log.info(`✅ Recovery successful for ${error.type}`);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
circuitBreaker.recordFailure();
|
|
333
|
+
// Increase backoff multiplier but don't delete context
|
|
334
|
+
context.backoffMultiplier = Math.min(context.backoffMultiplier * 2, 10);
|
|
335
|
+
// Keep the context so attemptCount persists
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
catch (recoveryError) {
|
|
339
|
+
log.error(`Recovery failed for ${error.type}:`, recoveryError);
|
|
340
|
+
circuitBreaker.recordFailure();
|
|
341
|
+
context.backoffMultiplier = Math.min(context.backoffMultiplier * 2, 10);
|
|
342
|
+
// Keep the context so attemptCount persists
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Backward compatibility wrapper
|
|
347
|
+
*/
|
|
348
|
+
async attemptRecovery(error) {
|
|
349
|
+
const circuitBreaker = this.getOrCreateCircuitBreaker(error.type);
|
|
350
|
+
if (this.shouldAttemptRecovery(error) && circuitBreaker.canAttempt()) {
|
|
351
|
+
await this.attemptContextualRecovery(error, circuitBreaker);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Get or create a circuit breaker for an error type
|
|
356
|
+
*/
|
|
357
|
+
getOrCreateCircuitBreaker(type) {
|
|
358
|
+
let breaker = this.circuitBreakers.get(type);
|
|
359
|
+
if (!breaker) {
|
|
360
|
+
breaker = new CircuitBreaker();
|
|
361
|
+
this.circuitBreakers.set(type, breaker);
|
|
362
|
+
}
|
|
363
|
+
return breaker;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Check if we should attempt recovery
|
|
367
|
+
*/
|
|
368
|
+
shouldAttemptRecovery(error) {
|
|
369
|
+
// Don't attempt recovery for non-recoverable errors
|
|
370
|
+
if (!error.recoverable) {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
// Check if we've exceeded max recovery attempts
|
|
374
|
+
const context = this.recoveryContexts.get(error.type);
|
|
375
|
+
if (context && context.attemptCount >= this.MAX_RECOVERY_ATTEMPTS) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Get contextual delay based on error type and attempt count
|
|
382
|
+
*/
|
|
383
|
+
getContextualDelay(type, attemptCount) {
|
|
384
|
+
// Base delays by error type
|
|
385
|
+
const baseDelays = {
|
|
386
|
+
[MatterErrorType.NETWORK]: 5000,
|
|
387
|
+
[MatterErrorType.STORAGE]: 1000,
|
|
388
|
+
[MatterErrorType.DEVICE_SYNC]: 2000,
|
|
389
|
+
[MatterErrorType.COMMISSIONING]: 3000,
|
|
390
|
+
[MatterErrorType.CONFIGURATION]: 1000,
|
|
391
|
+
[MatterErrorType.INITIALIZATION]: 2000,
|
|
392
|
+
[MatterErrorType.SERVER]: 1000,
|
|
393
|
+
[MatterErrorType.UNKNOWN]: 2000,
|
|
394
|
+
};
|
|
395
|
+
const baseDelay = baseDelays[type] || 2000;
|
|
396
|
+
// Exponential backoff with jitter
|
|
397
|
+
const backoffDelay = Math.min(baseDelay * 2 ** attemptCount, 30000);
|
|
398
|
+
const jitter = Math.random() * 1000;
|
|
399
|
+
return backoffDelay + jitter;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Register a recovery callback for specific error type
|
|
403
|
+
*/
|
|
404
|
+
registerRecoveryCallback(type, callback) {
|
|
405
|
+
const callbacks = this.recoveryCallbacks.get(type) || [];
|
|
406
|
+
callbacks.push(callback);
|
|
407
|
+
this.recoveryCallbacks.set(type, callbacks);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Reset error counts (useful after successful recovery)
|
|
411
|
+
*/
|
|
412
|
+
resetErrorCount(type) {
|
|
413
|
+
if (type) {
|
|
414
|
+
this.errorCount.delete(type);
|
|
415
|
+
this.lastErrors.delete(type);
|
|
416
|
+
this.recoveryContexts.delete(type);
|
|
417
|
+
// Reset circuit breaker
|
|
418
|
+
const circuitBreaker = this.circuitBreakers.get(type);
|
|
419
|
+
if (circuitBreaker) {
|
|
420
|
+
circuitBreaker.reset();
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
this.errorCount.clear();
|
|
425
|
+
this.lastErrors.clear();
|
|
426
|
+
this.recoveryContexts.clear();
|
|
427
|
+
// Reset all circuit breakers
|
|
428
|
+
for (const breaker of this.circuitBreakers.values()) {
|
|
429
|
+
breaker.reset();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get error statistics
|
|
435
|
+
*/
|
|
436
|
+
getErrorStats() {
|
|
437
|
+
const stats = new Map();
|
|
438
|
+
for (const [type, count] of this.errorCount) {
|
|
439
|
+
const lastError = this.lastErrors.get(type);
|
|
440
|
+
const circuitBreaker = this.circuitBreakers.get(type);
|
|
441
|
+
const context = this.recoveryContexts.get(type);
|
|
442
|
+
stats.set(type, {
|
|
443
|
+
count,
|
|
444
|
+
lastError,
|
|
445
|
+
circuitState: circuitBreaker?.getState(),
|
|
446
|
+
recoveryAttempts: context?.attemptCount,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
return stats;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Create a wrapped function with error handling
|
|
453
|
+
*/
|
|
454
|
+
wrapAsync(fn, context) {
|
|
455
|
+
return (async (...args) => {
|
|
456
|
+
try {
|
|
457
|
+
return await fn(...args);
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
await this.handleError(error, context);
|
|
461
|
+
throw error;
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Create a wrapped function with error suppression
|
|
467
|
+
*/
|
|
468
|
+
wrapAsyncSafe(fn, context, defaultValue) {
|
|
469
|
+
return (async (...args) => {
|
|
470
|
+
try {
|
|
471
|
+
return await fn(...args);
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
await this.handleError(error, context);
|
|
475
|
+
return defaultValue;
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
// Export singleton instance
|
|
481
|
+
export const errorHandler = MatterErrorHandler.getInstance();
|
|
482
|
+
//# sourceMappingURL=matterErrorHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matterErrorHandler.js","sourceRoot":"","sources":["../../src/matter/matterErrorHandler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;AAEvC,MAAM,CAAN,IAAY,eASX;AATD,WAAY,eAAe;IACzB,oDAAiC,CAAA;IACjC,sCAAmB,CAAA;IACnB,kDAA+B,CAAA;IAC/B,8CAA2B,CAAA;IAC3B,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;IACnB,kDAA+B,CAAA;IAC/B,sCAAmB,CAAA;AACrB,CAAC,EATW,eAAe,KAAf,eAAe,QAS1B;AAUD;;GAEG;AACH,IAAK,YAIJ;AAJD,WAAK,YAAY;IACf,iCAAiB,CAAA;IACjB,6BAAa,CAAA;IACb,uCAAuB,CAAA;AACzB,CAAC,EAJI,YAAY,KAAZ,YAAY,QAIhB;AAED;;GAEG;AACH,MAAM,cAAc;IAQC;IACA;IACA;IATX,KAAK,GAAG,YAAY,CAAC,MAAM,CAAA;IAC3B,YAAY,GAAG,CAAC,CAAA;IAChB,YAAY,GAAG,CAAC,CAAA;IAChB,eAAe,GAAG,CAAC,CAAA;IACnB,eAAe,GAAG,CAAC,CAAA;IAE3B,YACmB,YAAY,CAAC,EACb,UAAU,KAAK,EAAE,WAAW;IAC5B,mBAAmB,CAAC;QAFpB,cAAS,GAAT,SAAS,CAAI;QACb,YAAO,GAAP,OAAO,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O,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;YAC1B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,CAAC,WAAW,CAAC,KAAc,EAAE,OAAO,CAAC,CAAA;gBAC/C,MAAM,KAAK,CAAA;YACb,CAAC;QACH,CAAC,CAAM,CAAA;IACT,CAAC;IAED;;OAEG;IACH,aAAa,CACX,EAAK,EACL,OAAe,EACf,YAA4B;QAE5B,OAAO,CAAC,KAAK,EAAE,GAAG,IAAmB,EAAE,EAAE;YACvC,IAAI,CAAC;gBACH,OAAO,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;YAC1B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,CAAC,WAAW,CAAC,KAAc,EAAE,OAAO,CAAC,CAAA;gBAC/C,OAAO,YAAY,CAAA;YACrB,CAAC;QACH,CAAC,CAAM,CAAA;IACT,CAAC;CACF;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface NetworkStatus {
|
|
2
|
+
isOnline: boolean;
|
|
3
|
+
interfaces: string[];
|
|
4
|
+
primaryInterface?: string;
|
|
5
|
+
lastCheck: Date;
|
|
6
|
+
consecutiveFailures: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class MatterNetworkMonitor {
|
|
9
|
+
private static instance;
|
|
10
|
+
private status;
|
|
11
|
+
private checkInterval;
|
|
12
|
+
private callbacks;
|
|
13
|
+
private checkIntervalMs;
|
|
14
|
+
private isMonitoring;
|
|
15
|
+
private stabilityCounter;
|
|
16
|
+
private readonly STABILITY_THRESHOLD;
|
|
17
|
+
private constructor();
|
|
18
|
+
static getInstance(): MatterNetworkMonitor;
|
|
19
|
+
/**
|
|
20
|
+
* Start monitoring network connectivity
|
|
21
|
+
*/
|
|
22
|
+
startMonitoring(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Stop monitoring
|
|
25
|
+
*/
|
|
26
|
+
stopMonitoring(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Check network status
|
|
29
|
+
*/
|
|
30
|
+
private checkNetworkStatus;
|
|
31
|
+
/**
|
|
32
|
+
* Get active network interfaces
|
|
33
|
+
*/
|
|
34
|
+
private getActiveInterfaces;
|
|
35
|
+
/**
|
|
36
|
+
* Test network connectivity with optimizations
|
|
37
|
+
*/
|
|
38
|
+
private testConnectivity;
|
|
39
|
+
/**
|
|
40
|
+
* Handle network recovery
|
|
41
|
+
*/
|
|
42
|
+
private handleNetworkRecovery;
|
|
43
|
+
/**
|
|
44
|
+
* Register a callback for network status changes
|
|
45
|
+
*/
|
|
46
|
+
onStatusChange(callback: (status: NetworkStatus) => void): void;
|
|
47
|
+
/**
|
|
48
|
+
* Remove a status change callback
|
|
49
|
+
*/
|
|
50
|
+
removeStatusChangeCallback(callback: (status: NetworkStatus) => void): void;
|
|
51
|
+
/**
|
|
52
|
+
* Notify all listeners of status change
|
|
53
|
+
*/
|
|
54
|
+
private notifyStatusChange;
|
|
55
|
+
/**
|
|
56
|
+
* Get current network status
|
|
57
|
+
*/
|
|
58
|
+
getStatus(): NetworkStatus;
|
|
59
|
+
/**
|
|
60
|
+
* Check if network is healthy
|
|
61
|
+
*/
|
|
62
|
+
isHealthy(): boolean;
|
|
63
|
+
}
|
|
64
|
+
export declare const networkMonitor: MatterNetworkMonitor;
|
|
65
|
+
//# sourceMappingURL=matterNetworkMonitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matterNetworkMonitor.d.ts","sourceRoot":"","sources":["../../src/matter/matterNetworkMonitor.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,EAAE,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