homebridge 2.0.0-alpha.40 → 2.0.0-alpha.42
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/config-sample.json +1 -12
- package/dist/api.d.ts +46 -35
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +41 -35
- package/dist/api.js.map +1 -1
- package/dist/bridgeService.d.ts +7 -15
- package/dist/bridgeService.d.ts.map +1 -1
- package/dist/bridgeService.js +10 -7
- package/dist/bridgeService.js.map +1 -1
- package/dist/childBridgeFork.d.ts +19 -0
- package/dist/childBridgeFork.d.ts.map +1 -1
- package/dist/childBridgeFork.js +198 -4
- package/dist/childBridgeFork.js.map +1 -1
- package/dist/childBridgeService.d.ts +28 -1
- package/dist/childBridgeService.d.ts.map +1 -1
- package/dist/childBridgeService.js +43 -0
- package/dist/childBridgeService.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/ipcService.d.ts +21 -3
- package/dist/ipcService.d.ts.map +1 -1
- package/dist/ipcService.js +15 -0
- package/dist/ipcService.js.map +1 -1
- package/dist/matter/index.d.ts +11 -0
- package/dist/matter/index.d.ts.map +1 -0
- package/dist/matter/index.js +11 -0
- package/dist/matter/index.js.map +1 -0
- package/dist/matter/matterConfigValidator.d.ts +26 -0
- package/dist/matter/matterConfigValidator.d.ts.map +1 -0
- package/dist/matter/matterConfigValidator.js +171 -0
- package/dist/matter/matterConfigValidator.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 +94 -0
- package/dist/matter/matterErrorHandler.d.ts.map +1 -0
- package/dist/matter/matterErrorHandler.js +472 -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 +196 -0
- package/dist/matter/matterServer.d.ts.map +1 -0
- package/dist/matter/matterServer.js +824 -0
- package/dist/matter/matterServer.js.map +1 -0
- package/dist/matter/matterSharedTypes.d.ts +147 -0
- package/dist/matter/matterSharedTypes.d.ts.map +1 -0
- package/dist/matter/matterSharedTypes.js +51 -0
- package/dist/matter/matterSharedTypes.js.map +1 -0
- package/dist/matter/matterStorage.d.ts +112 -0
- package/dist/matter/matterStorage.d.ts.map +1 -0
- package/dist/matter/matterStorage.js +355 -0
- package/dist/matter/matterStorage.js.map +1 -0
- package/dist/matter/matterTypes.d.ts +163 -0
- package/dist/matter/matterTypes.d.ts.map +1 -0
- package/dist/matter/matterTypes.js +106 -0
- package/dist/matter/matterTypes.js.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +4 -2
- package/dist/plugin.js.map +1 -1
- package/dist/server.d.ts +18 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +361 -51
- package/dist/server.js.map +1 -1
- package/dist/user.d.ts +1 -0
- package/dist/user.d.ts.map +1 -1
- package/dist/user.js +3 -0
- package/dist/user.js.map +1 -1
- package/package.json +12 -13
- package/dist/matterConfigValidator.d.ts +0 -34
- package/dist/matterConfigValidator.d.ts.map +0 -1
- package/dist/matterConfigValidator.js +0 -249
- package/dist/matterConfigValidator.js.map +0 -1
- package/dist/matterService.d.ts +0 -168
- package/dist/matterService.d.ts.map +0 -1
- package/dist/matterService.js +0 -677
- package/dist/matterService.js.map +0 -1
- package/dist/matterTypes.d.ts +0 -20
- package/dist/matterTypes.d.ts.map +0 -1
- package/dist/matterTypes.js +0 -278
- package/dist/matterTypes.js.map +0 -1
- package/dist/util/matter-cli.d.ts +0 -3
- package/dist/util/matter-cli.d.ts.map +0 -1
- package/dist/util/matter-cli.js +0 -211
- package/dist/util/matter-cli.js.map +0 -1
|
@@ -0,0 +1,472 @@
|
|
|
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
|
+
import { MatterCommissioningError, MatterDeviceError, MatterError, MatterErrorType, MatterNetworkError, MatterStorageError, } from './matterTypes.js';
|
|
9
|
+
const log = Logger.withPrefix('Matter');
|
|
10
|
+
// Re-export for backward compatibility
|
|
11
|
+
export { MatterCommissioningError, MatterDeviceError, MatterError, MatterErrorType, MatterNetworkError, MatterStorageError };
|
|
12
|
+
/**
|
|
13
|
+
* Circuit breaker states
|
|
14
|
+
*/
|
|
15
|
+
var CircuitState;
|
|
16
|
+
(function (CircuitState) {
|
|
17
|
+
CircuitState["CLOSED"] = "CLOSED";
|
|
18
|
+
CircuitState["OPEN"] = "OPEN";
|
|
19
|
+
CircuitState["HALF_OPEN"] = "HALF_OPEN";
|
|
20
|
+
})(CircuitState || (CircuitState = {}));
|
|
21
|
+
/**
|
|
22
|
+
* Circuit breaker for error recovery
|
|
23
|
+
*/
|
|
24
|
+
class CircuitBreaker {
|
|
25
|
+
threshold;
|
|
26
|
+
timeout;
|
|
27
|
+
successThreshold;
|
|
28
|
+
state = CircuitState.CLOSED;
|
|
29
|
+
failureCount = 0;
|
|
30
|
+
successCount = 0;
|
|
31
|
+
nextAttemptTime = 0;
|
|
32
|
+
constructor(threshold = 5, timeout = 60000, // 1 minute
|
|
33
|
+
successThreshold = 3) {
|
|
34
|
+
this.threshold = threshold;
|
|
35
|
+
this.timeout = timeout;
|
|
36
|
+
this.successThreshold = successThreshold;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if operation should be allowed
|
|
40
|
+
*/
|
|
41
|
+
canAttempt() {
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
switch (this.state) {
|
|
44
|
+
case CircuitState.CLOSED:
|
|
45
|
+
return true;
|
|
46
|
+
case CircuitState.OPEN:
|
|
47
|
+
if (now >= this.nextAttemptTime) {
|
|
48
|
+
this.state = CircuitState.HALF_OPEN;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
case CircuitState.HALF_OPEN:
|
|
53
|
+
return true;
|
|
54
|
+
default:
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Record success
|
|
60
|
+
*/
|
|
61
|
+
recordSuccess() {
|
|
62
|
+
this.failureCount = 0;
|
|
63
|
+
if (this.state === CircuitState.HALF_OPEN) {
|
|
64
|
+
this.successCount++;
|
|
65
|
+
if (this.successCount >= this.successThreshold) {
|
|
66
|
+
this.state = CircuitState.CLOSED;
|
|
67
|
+
this.successCount = 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Record failure
|
|
73
|
+
*/
|
|
74
|
+
recordFailure() {
|
|
75
|
+
this.failureCount++;
|
|
76
|
+
this.successCount = 0;
|
|
77
|
+
if (this.state === CircuitState.HALF_OPEN) {
|
|
78
|
+
this.state = CircuitState.OPEN;
|
|
79
|
+
this.nextAttemptTime = Date.now() + this.timeout;
|
|
80
|
+
}
|
|
81
|
+
else if (this.failureCount >= this.threshold) {
|
|
82
|
+
this.state = CircuitState.OPEN;
|
|
83
|
+
this.nextAttemptTime = Date.now() + this.timeout;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get current state
|
|
88
|
+
*/
|
|
89
|
+
getState() {
|
|
90
|
+
return this.state;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Reset the circuit breaker
|
|
94
|
+
*/
|
|
95
|
+
reset() {
|
|
96
|
+
this.state = CircuitState.CLOSED;
|
|
97
|
+
this.failureCount = 0;
|
|
98
|
+
this.successCount = 0;
|
|
99
|
+
this.nextAttemptTime = 0;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export class MatterErrorHandler {
|
|
103
|
+
static instance;
|
|
104
|
+
errorCount = new Map();
|
|
105
|
+
lastErrors = new Map();
|
|
106
|
+
recoveryCallbacks = new Map();
|
|
107
|
+
circuitBreakers = new Map();
|
|
108
|
+
recoveryContexts = new Map();
|
|
109
|
+
MAX_RECOVERY_ATTEMPTS = 5;
|
|
110
|
+
constructor() { }
|
|
111
|
+
static getInstance() {
|
|
112
|
+
if (!MatterErrorHandler.instance) {
|
|
113
|
+
MatterErrorHandler.instance = new MatterErrorHandler();
|
|
114
|
+
}
|
|
115
|
+
return MatterErrorHandler.instance;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Handle a Matter error with context-aware recovery
|
|
119
|
+
*/
|
|
120
|
+
async handleError(error, context) {
|
|
121
|
+
const matterError = this.categorizeError(error, context);
|
|
122
|
+
// Log the error with appropriate level
|
|
123
|
+
this.logError(matterError);
|
|
124
|
+
// Track error occurrence
|
|
125
|
+
this.trackError(matterError);
|
|
126
|
+
// Check circuit breaker before attempting recovery
|
|
127
|
+
const circuitBreaker = this.getOrCreateCircuitBreaker(matterError.type);
|
|
128
|
+
if (matterError.recoverable && circuitBreaker.canAttempt()) {
|
|
129
|
+
// Check if we should attempt recovery based on context
|
|
130
|
+
if (this.shouldAttemptRecovery(matterError)) {
|
|
131
|
+
this.attemptContextualRecovery(matterError, circuitBreaker).catch((err) => {
|
|
132
|
+
log.debug(`Recovery attempt failed for ${matterError.type}:`, err);
|
|
133
|
+
circuitBreaker.recordFailure();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (!circuitBreaker.canAttempt()) {
|
|
138
|
+
log.debug(`Circuit breaker OPEN for ${matterError.type}, skipping recovery`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Categorize error into Matter error types
|
|
143
|
+
*/
|
|
144
|
+
categorizeError(error, context) {
|
|
145
|
+
// If already a typed MatterError, return it
|
|
146
|
+
if (error instanceof MatterError) {
|
|
147
|
+
return error;
|
|
148
|
+
}
|
|
149
|
+
// Create specific error types based on error message and context
|
|
150
|
+
if (error.message.includes('EADDRINUSE')) {
|
|
151
|
+
return new MatterNetworkError(`Port is already in use: ${error.message}`, { code: 'PORT_IN_USE', recoverable: false, type: MatterErrorType.NETWORK });
|
|
152
|
+
}
|
|
153
|
+
else if (error.message.includes('ECONNREFUSED') || error.message.includes('ETIMEDOUT')) {
|
|
154
|
+
return new MatterNetworkError(`Connection failed: ${error.message}`, { code: 'CONNECTION_FAILED', recoverable: true, type: MatterErrorType.NETWORK });
|
|
155
|
+
}
|
|
156
|
+
else if (error.message.includes('commissioning') || error.message.includes('pairing')) {
|
|
157
|
+
return new MatterCommissioningError(`Commissioning error: ${error.message}`, { recoverable: false, type: MatterErrorType.COMMISSIONING });
|
|
158
|
+
}
|
|
159
|
+
else if (error.message.includes('storage') || error.message.includes('ENOENT')) {
|
|
160
|
+
return new MatterStorageError(`Storage error: ${error.message}`, { recoverable: true, type: MatterErrorType.STORAGE });
|
|
161
|
+
}
|
|
162
|
+
else if (error.message.includes('config') || error.message.includes('invalid')) {
|
|
163
|
+
return new MatterError(`Configuration error: ${error.message}`, 'CONFIGURATION_ERROR', { recoverable: false, type: MatterErrorType.CONFIGURATION });
|
|
164
|
+
}
|
|
165
|
+
else if (context?.includes('sync') || context?.includes('device')) {
|
|
166
|
+
return new MatterDeviceError(`Device sync error: ${error.message}`, { recoverable: true, type: MatterErrorType.DEVICE_SYNC, context });
|
|
167
|
+
}
|
|
168
|
+
else if (context?.includes('server')) {
|
|
169
|
+
return new MatterError(`Server error: ${error.message}`, 'SERVER_ERROR', { recoverable: true, type: MatterErrorType.SERVER, context });
|
|
170
|
+
}
|
|
171
|
+
else if (context?.includes('init')) {
|
|
172
|
+
return new MatterError(`Initialization error: ${error.message}`, 'INITIALIZATION_ERROR', { recoverable: true, type: MatterErrorType.INITIALIZATION, context });
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return new MatterError(error.message || 'Unknown Matter error', 'UNKNOWN_ERROR', { recoverable: false, type: MatterErrorType.UNKNOWN, originalError: error });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Log error with appropriate severity
|
|
180
|
+
*/
|
|
181
|
+
logError(error) {
|
|
182
|
+
// Get the error type from the details if available, otherwise try to determine it
|
|
183
|
+
const details = error.details;
|
|
184
|
+
const errorType = details?.type || this.getErrorType(error);
|
|
185
|
+
const errorCount = this.errorCount.get(errorType) || 0;
|
|
186
|
+
const recoverable = details?.recoverable !== false;
|
|
187
|
+
if (error instanceof MatterNetworkError) {
|
|
188
|
+
if (details?.code === 'PORT_IN_USE') {
|
|
189
|
+
log.error('Matter port is already in use. Please configure a different port.');
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
log.warn(`Matter network error: ${error.message}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if (error instanceof MatterCommissioningError) {
|
|
196
|
+
log.info(`Matter commissioning issue: ${error.message}`);
|
|
197
|
+
}
|
|
198
|
+
else if (error instanceof MatterDeviceError) {
|
|
199
|
+
if (errorCount < 3) {
|
|
200
|
+
log.debug(`Device sync error: ${error.message}`);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
log.warn(`Repeated device sync errors: ${error.message}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (error instanceof MatterStorageError) {
|
|
207
|
+
log.warn(`Matter storage error: ${error.message}`);
|
|
208
|
+
}
|
|
209
|
+
else if (error.code === 'CONFIGURATION_ERROR') {
|
|
210
|
+
log.error(`Matter configuration error: ${error.message}`);
|
|
211
|
+
}
|
|
212
|
+
else if (error.code === 'SERVER_ERROR') {
|
|
213
|
+
log.error(`Matter server error: ${error.message}`);
|
|
214
|
+
}
|
|
215
|
+
else if (error.code === 'INITIALIZATION_ERROR') {
|
|
216
|
+
log.error(`Matter initialization error: ${error.message}`);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
log.error(`Matter error: ${error.message}`);
|
|
220
|
+
}
|
|
221
|
+
// Log stack trace for non-recoverable errors
|
|
222
|
+
if (!recoverable && error.stack) {
|
|
223
|
+
log.debug('Stack trace:', error.stack);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Get error type from MatterError
|
|
228
|
+
*/
|
|
229
|
+
getErrorType(error) {
|
|
230
|
+
if (error instanceof MatterNetworkError) {
|
|
231
|
+
return MatterErrorType.NETWORK;
|
|
232
|
+
}
|
|
233
|
+
else if (error instanceof MatterCommissioningError) {
|
|
234
|
+
return MatterErrorType.COMMISSIONING;
|
|
235
|
+
}
|
|
236
|
+
else if (error instanceof MatterDeviceError) {
|
|
237
|
+
return MatterErrorType.DEVICE_SYNC;
|
|
238
|
+
}
|
|
239
|
+
else if (error instanceof MatterStorageError) {
|
|
240
|
+
return MatterErrorType.STORAGE;
|
|
241
|
+
}
|
|
242
|
+
else if (error.code === 'CONFIGURATION_ERROR') {
|
|
243
|
+
return MatterErrorType.CONFIGURATION;
|
|
244
|
+
}
|
|
245
|
+
else if (error.code === 'SERVER_ERROR') {
|
|
246
|
+
return MatterErrorType.SERVER;
|
|
247
|
+
}
|
|
248
|
+
else if (error.code === 'INITIALIZATION_ERROR') {
|
|
249
|
+
return MatterErrorType.INITIALIZATION;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
return MatterErrorType.UNKNOWN;
|
|
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
|
+
const errorType = this.getErrorType(error);
|
|
263
|
+
if (!this.errorCount.has(errorType) && this.errorCount.size >= MAX_ERROR_TYPES) {
|
|
264
|
+
// Remove oldest error type
|
|
265
|
+
const firstKey = this.errorCount.keys().next().value;
|
|
266
|
+
if (firstKey) {
|
|
267
|
+
this.errorCount.delete(firstKey);
|
|
268
|
+
this.lastErrors.delete(firstKey);
|
|
269
|
+
this.recoveryContexts.delete(firstKey);
|
|
270
|
+
this.circuitBreakers.delete(firstKey);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const count = (this.errorCount.get(error.type) || 0) + 1;
|
|
274
|
+
// Cap error count per type
|
|
275
|
+
this.errorCount.set(error.type, Math.min(count, MAX_ERRORS_PER_TYPE));
|
|
276
|
+
this.lastErrors.set(error.type, error);
|
|
277
|
+
// Auto-cleanup old errors after 1 hour
|
|
278
|
+
setTimeout(() => {
|
|
279
|
+
const currentError = this.lastErrors.get(error.type);
|
|
280
|
+
if (currentError && currentError.timestamp === error.timestamp) {
|
|
281
|
+
this.clearErrors(error.type);
|
|
282
|
+
}
|
|
283
|
+
}, 3600000); // 1 hour
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Clear errors for a specific type
|
|
287
|
+
*/
|
|
288
|
+
clearErrors(errorType) {
|
|
289
|
+
this.errorCount.delete(errorType);
|
|
290
|
+
this.lastErrors.delete(errorType);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Attempt contextual recovery from error
|
|
294
|
+
*/
|
|
295
|
+
async attemptContextualRecovery(error, circuitBreaker) {
|
|
296
|
+
// Get or create recovery context
|
|
297
|
+
let context = this.recoveryContexts.get(error.type);
|
|
298
|
+
if (!context) {
|
|
299
|
+
context = {
|
|
300
|
+
errorType: error.type,
|
|
301
|
+
attemptCount: 0,
|
|
302
|
+
lastAttemptTime: 0,
|
|
303
|
+
backoffMultiplier: 1,
|
|
304
|
+
};
|
|
305
|
+
this.recoveryContexts.set(error.type, context);
|
|
306
|
+
}
|
|
307
|
+
context.attemptCount++;
|
|
308
|
+
context.lastAttemptTime = Date.now();
|
|
309
|
+
const delay = this.getContextualDelay(error.type, context.attemptCount - 1);
|
|
310
|
+
log.info(`Attempting recovery from ${error.type} error (attempt ${context.attemptCount}) in ${delay}ms`);
|
|
311
|
+
// Use global.setTimeout so it can be mocked in tests
|
|
312
|
+
await new Promise(resolve => globalThis.setTimeout(resolve, delay));
|
|
313
|
+
try {
|
|
314
|
+
const callbacks = this.recoveryCallbacks.get(error.type) || [];
|
|
315
|
+
let anySuccess = false;
|
|
316
|
+
for (const callback of callbacks) {
|
|
317
|
+
try {
|
|
318
|
+
await callback();
|
|
319
|
+
anySuccess = true;
|
|
320
|
+
}
|
|
321
|
+
catch (callbackError) {
|
|
322
|
+
log.debug(`Recovery callback failed for ${error.type}:`, callbackError);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (anySuccess) {
|
|
326
|
+
circuitBreaker.recordSuccess();
|
|
327
|
+
// Reset context on success
|
|
328
|
+
this.recoveryContexts.delete(error.type);
|
|
329
|
+
this.errorCount.set(error.type, 0);
|
|
330
|
+
log.info(`Recovery successful for ${error.type}`);
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
circuitBreaker.recordFailure();
|
|
334
|
+
// Increase backoff multiplier but don't delete context
|
|
335
|
+
context.backoffMultiplier = Math.min(context.backoffMultiplier * 2, 10);
|
|
336
|
+
// Keep the context so attemptCount persists
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
catch (recoveryError) {
|
|
340
|
+
log.error(`Recovery failed for ${error.type}:`, recoveryError);
|
|
341
|
+
circuitBreaker.recordFailure();
|
|
342
|
+
context.backoffMultiplier = Math.min(context.backoffMultiplier * 2, 10);
|
|
343
|
+
// Keep the context so attemptCount persists
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Get or create a circuit breaker for an error type
|
|
348
|
+
*/
|
|
349
|
+
getOrCreateCircuitBreaker(type) {
|
|
350
|
+
let breaker = this.circuitBreakers.get(type);
|
|
351
|
+
if (!breaker) {
|
|
352
|
+
breaker = new CircuitBreaker();
|
|
353
|
+
this.circuitBreakers.set(type, breaker);
|
|
354
|
+
}
|
|
355
|
+
return breaker;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Check if we should attempt recovery
|
|
359
|
+
*/
|
|
360
|
+
shouldAttemptRecovery(error) {
|
|
361
|
+
// Don't attempt recovery for non-recoverable errors
|
|
362
|
+
if (!error.recoverable) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
// Check if we've exceeded max recovery attempts
|
|
366
|
+
const context = this.recoveryContexts.get(error.type);
|
|
367
|
+
return !(context && context.attemptCount >= this.MAX_RECOVERY_ATTEMPTS);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get contextual delay based on error type and attempt count
|
|
371
|
+
*/
|
|
372
|
+
getContextualDelay(type, attemptCount) {
|
|
373
|
+
// Base delays by error type
|
|
374
|
+
const baseDelays = {
|
|
375
|
+
[MatterErrorType.NETWORK]: 5000,
|
|
376
|
+
[MatterErrorType.STORAGE]: 1000,
|
|
377
|
+
[MatterErrorType.DEVICE_SYNC]: 2000,
|
|
378
|
+
[MatterErrorType.DEVICE_ERROR]: 2000,
|
|
379
|
+
[MatterErrorType.COMMISSIONING]: 3000,
|
|
380
|
+
[MatterErrorType.CONFIGURATION]: 1000,
|
|
381
|
+
[MatterErrorType.INITIALIZATION]: 2000,
|
|
382
|
+
[MatterErrorType.SERVER]: 1000,
|
|
383
|
+
[MatterErrorType.UNKNOWN]: 2000,
|
|
384
|
+
};
|
|
385
|
+
const baseDelay = baseDelays[type] || 2000;
|
|
386
|
+
// Exponential backoff with jitter
|
|
387
|
+
const backoffDelay = Math.min(baseDelay * 2 ** attemptCount, 30000);
|
|
388
|
+
const jitter = Math.random() * 1000;
|
|
389
|
+
return backoffDelay + jitter;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Register a recovery callback for specific error type
|
|
393
|
+
*/
|
|
394
|
+
registerRecoveryCallback(type, callback) {
|
|
395
|
+
const callbacks = this.recoveryCallbacks.get(type) || [];
|
|
396
|
+
callbacks.push(callback);
|
|
397
|
+
this.recoveryCallbacks.set(type, callbacks);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Reset error counts (useful after successful recovery)
|
|
401
|
+
*/
|
|
402
|
+
resetErrorCount(type) {
|
|
403
|
+
if (type) {
|
|
404
|
+
this.errorCount.delete(type);
|
|
405
|
+
this.lastErrors.delete(type);
|
|
406
|
+
this.recoveryContexts.delete(type);
|
|
407
|
+
// Reset circuit breaker
|
|
408
|
+
const circuitBreaker = this.circuitBreakers.get(type);
|
|
409
|
+
if (circuitBreaker) {
|
|
410
|
+
circuitBreaker.reset();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
this.errorCount.clear();
|
|
415
|
+
this.lastErrors.clear();
|
|
416
|
+
this.recoveryContexts.clear();
|
|
417
|
+
// Reset all circuit breakers
|
|
418
|
+
for (const breaker of this.circuitBreakers.values()) {
|
|
419
|
+
breaker.reset();
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Get error statistics
|
|
425
|
+
*/
|
|
426
|
+
getErrorStats() {
|
|
427
|
+
const stats = new Map();
|
|
428
|
+
for (const [type, count] of this.errorCount) {
|
|
429
|
+
const lastError = this.lastErrors.get(type);
|
|
430
|
+
const circuitBreaker = this.circuitBreakers.get(type);
|
|
431
|
+
const context = this.recoveryContexts.get(type);
|
|
432
|
+
stats.set(type, {
|
|
433
|
+
count,
|
|
434
|
+
lastError,
|
|
435
|
+
circuitState: circuitBreaker?.getState(),
|
|
436
|
+
recoveryAttempts: context?.attemptCount,
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return stats;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Create a wrapped function with error handling
|
|
443
|
+
*/
|
|
444
|
+
wrapAsync(fn, context) {
|
|
445
|
+
return (async (...args) => {
|
|
446
|
+
try {
|
|
447
|
+
return await fn(...args);
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
await this.handleError(error, context);
|
|
451
|
+
throw error;
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Create a wrapped function with error suppression
|
|
457
|
+
*/
|
|
458
|
+
wrapAsyncSafe(fn, context, defaultValue) {
|
|
459
|
+
return (async (...args) => {
|
|
460
|
+
try {
|
|
461
|
+
return await fn(...args);
|
|
462
|
+
}
|
|
463
|
+
catch (error) {
|
|
464
|
+
await this.handleError(error, context);
|
|
465
|
+
return defaultValue;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// Export singleton instance
|
|
471
|
+
export const errorHandler = MatterErrorHandler.getInstance();
|
|
472
|
+
//# 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;AACrC,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,kBAAkB,CAAA;AAEzB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;AAEvC,uCAAuC;AACvC,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBA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AAE,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,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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