- extractErrorMessage(err: unknown) normalizes any error shape to string - handleError/handleInfraError dual utilities (user-facing vs infra-only) - error-classifier extended with ipc/database/filesystem types (9 total) - Toast rate-limiting (max 3 per type per 30s) in notifications store - Infrastructure bridges use documented console.warn (recursion prevention) - 13 new tests for extractErrorMessage
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
// Telemetry bridge — routes frontend events to Rust tracing via IPC
|
|
// No browser OTEL SDK needed (WebKit2GTK incompatible)
|
|
|
|
import { invoke } from '@tauri-apps/api/core';
|
|
|
|
type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
|
|
/** Emit a structured log event to the Rust tracing layer */
|
|
export function telemetryLog(
|
|
level: LogLevel,
|
|
message: string,
|
|
context?: Record<string, unknown>,
|
|
): void {
|
|
invoke('frontend_log', { level, message, context: context ?? null }).catch((_e: unknown) => {
|
|
// Intentional: telemetry must never break the app or trigger notification loops.
|
|
// Cannot use handleInfraError here — it calls tel.error which would recurse.
|
|
// eslint-disable-next-line no-console
|
|
console.warn('[telemetry-bridge] IPC failed:', _e);
|
|
});
|
|
}
|
|
|
|
/** Convenience wrappers */
|
|
export const tel = {
|
|
error: (msg: string, ctx?: Record<string, unknown>) => telemetryLog('error', msg, ctx),
|
|
warn: (msg: string, ctx?: Record<string, unknown>) => telemetryLog('warn', msg, ctx),
|
|
info: (msg: string, ctx?: Record<string, unknown>) => telemetryLog('info', msg, ctx),
|
|
debug: (msg: string, ctx?: Record<string, unknown>) => telemetryLog('debug', msg, ctx),
|
|
trace: (msg: string, ctx?: Record<string, unknown>) => telemetryLog('trace', msg, ctx),
|
|
};
|