UNPKG

matterbridge-dyson-robot

Version:

A Matterbridge plugin that connects Dyson robot vacuums and air treatment devices to the Matter smart home ecosystem via their local or cloud MQTT APIs.

40 lines 1.69 kB
// Matterbridge plugin for Dyson robot vacuum and air treatment devices // Copyright © 2025-2026 Alexander Thoukydides // Log an error let lastLoggedError; export function logError(log, when, err) { try { // Suppress duplicate reports if (lastLoggedError === err) return err; lastLoggedError = err; // Log the top-level error message const message = err instanceof Error ? `${err.name}: ${err.message}` : String(err); log.error(`[${when}] ${message}`); const prefix = ' '.repeat(when.length + 3); // Log any history of causes or sub-errors logSubErrors(log, prefix, err); // Log any stack backtrace (for the top-level error only) if (err instanceof Error && err.stack) log.debug(err.stack); } catch { /* empty */ } return err; } // Log any sub-errors (causes or aggregates) of an error, formatted as a tree function logSubErrors(log, prefix, err) { // Collect all aggregate or causal errors const subErrs = []; if (err instanceof Error && err.cause) subErrs.push(err.cause); if (err instanceof AggregateError && Array.isArray(err.errors)) subErrs.push(...err.errors); // Log the collected errors formatted as a tree subErrs.forEach((subErr, index) => { const subPrefix = index < subErrs.length - 1 ? ['├─', '│ '] : ['└─', ' ']; const message = subErr instanceof Error ? `${subErr.name}: ${subErr.message}` : String(subErr); log.error(`${prefix}${subPrefix[0]} ${message}`); logSubErrors(log, `${prefix}${subPrefix[1]} `, subErr); }); } //# sourceMappingURL=log-error.js.map