smart-home-engine 1.20.6 → 1.20.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-home-engine",
3
- "version": "1.20.6",
3
+ "version": "1.20.7",
4
4
  "description": "Node.js based script runner for use in MQTT based Smart Home environments",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -18,6 +18,13 @@ const COMMISSION_TIMEOUT_MS = 120000;
18
18
  /** @type {import('@matter/main').ServerNode | null} */
19
19
  let _server = null;
20
20
  let _log = null;
21
+ // Rate-limit state for repeating matter.js error lines (B6)
22
+ let _lastMatterErr = { line: '', ts: 0, suppressed: 0 };
23
+
24
+ /** Depth-limited, cycle-safe rendering of arbitrary throwables/objects. */
25
+ function _inspect(v) {
26
+ return require('util').inspect(v, { depth: 6, breakLength: 160 });
27
+ }
21
28
  /** @type {((msg: object) => void) | null} */
22
29
  let _broadcast = null;
23
30
 
@@ -115,9 +122,49 @@ async function init(storagePath, log, broadcastFn) {
115
122
  Logger.format = LogFormat.PLAIN;
116
123
  Logger.level = LogLevel.INFO;
117
124
  Logger.destinations.default.write = (text, message) => {
118
- if (message.level >= LogLevel.ERROR) _log.error('matter.js:', text);
119
- else if (message.level === LogLevel.WARN) _log.warn('matter.js:', text);
120
- else _log.debug('matter.js:', text);
125
+ // she's log adds its own timestamp — drop matter.js's embedded one
126
+ let line = text.replace(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\s*/, '');
127
+ if (message.level >= LogLevel.ERROR) {
128
+ // PLAIN formatting renders some throwables as "{}" — recover the
129
+ // detail from the structured message values (B6).
130
+ if (/(\{\}|\[object \w+\])\s*$/.test(line)) {
131
+ const details = (message.values ?? [])
132
+ .filter((v) => v !== null && typeof v === 'object')
133
+ .map((v) => _inspect(v))
134
+ .filter((d) => d && d !== '{}');
135
+ if (details.length) line += ' — ' + details.join(' — ');
136
+ }
137
+ // Rate-limit identical repeating error lines (e.g. a failing
138
+ // reconnect loop): suppress repeats within 30 s, keep a heartbeat.
139
+ const now = Date.now();
140
+ if (line === _lastMatterErr.line && now - _lastMatterErr.ts < 30000) {
141
+ _lastMatterErr.ts = now;
142
+ _lastMatterErr.suppressed++;
143
+ if (_lastMatterErr.suppressed % 20 !== 0) return;
144
+ _log.error(`matter.js: (error repeated ${_lastMatterErr.suppressed} times) ${line}`);
145
+ return;
146
+ }
147
+ if (_lastMatterErr.suppressed % 20 !== 0) {
148
+ _log.error(`matter.js: (previous error repeated ${_lastMatterErr.suppressed} more times)`);
149
+ }
150
+ _lastMatterErr = { line, ts: now, suppressed: 0 };
151
+ _log.error('matter.js:', line);
152
+ } else if (message.level === LogLevel.WARN) {
153
+ _log.warn('matter.js:', line);
154
+ } else {
155
+ _log.debug('matter.js:', line);
156
+ }
157
+ };
158
+
159
+ // matter.js's default unhandled-error reporter logs the bare value, which
160
+ // renders as "{}" for non-Error throwables and drops cause / AggregateError
161
+ // details. The hook is explicitly replaceable — report full detail (B6).
162
+ Logger.reportUnhandledError = (error) => {
163
+ try {
164
+ _log.error('matter.js: unhandled error:', _inspect(error));
165
+ } catch {
166
+ /* never throw from the error reporter */
167
+ }
121
168
  };
122
169
 
123
170
  // Configure storage before anything else touches StorageService