A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
refactor(desktop): reuse shared error message formatting
Hampus601b4320bbea
diff --git a/fluxer_desktop/src/main/AppImageUpdate.ts b/fluxer_desktop/src/main/AppImageUpdate.tsindex b3fe4da29..5b177abed 100644--- a/fluxer_desktop/src/main/AppImageUpdate.ts+++ b/fluxer_desktop/src/main/AppImageUpdate.ts@@ -16,6 +16,7 @@ import {} from 'node:fs';import {open} from 'node:fs/promises';import {basename, dirname, join, resolve, sep} from 'node:path';+import {errorMessage} from '@electron/common/ErrorMessage';type AppImageUnavailableReason =| 'appimage-path-missing'@@ -45,7 +46,7 @@ const APPDIR_ENTRYPOINT = 'AppRun';const APPIMAGE_MODE = 0o755;const SHA256_PATTERN = /^[0-9a-f]{64}$/;const STAGING_FREE_SPACE_MARGIN_BYTES = 16 * 1024 * 1024;-export const APPIMAGE_DOWNLOAD_STALL_MS = 30_000;+const APPIMAGE_DOWNLOAD_STALL_MS = 30_000;const NON_RETRYABLE_STAGING_ERRNOS = new Set(['ENOSPC','EDQUOT',@@ -58,14 +59,14 @@ const NON_RETRYABLE_STAGING_ERRNOS = new Set(['ENOSYS',]);-export class AppImageChecksumError extends Error {+class AppImageChecksumError extends Error {constructor(expected: string, actual: string) {super(`Update checksum mismatch: expected ${expected}, downloaded ${actual}`);this.name = 'AppImageChecksumError';}}-export class AppImageStagingError extends Error {+class AppImageStagingError extends Error {readonly code: string;constructor(code: string, message: string) {@@ -90,7 +91,7 @@ function asStagingError(error: unknown): unknown {if (code === null || !NON_RETRYABLE_STAGING_ERRNOS.has(code)) {return error;}- return new AppImageStagingError(code, error instanceof Error ? error.message : String(error));+ return new AppImageStagingError(code, errorMessage(error));}function stagingDirectoryPrefix(installedPath: string): string {@@ -293,7 +294,7 @@ export function applyStagedAppImageUpdate(target: AppImageTarget, staged: StageddiscardStagedAppImageUpdate(staged);}-export function discardStagedAppImageUpdate(staged: StagedAppImageUpdate): void {+function discardStagedAppImageUpdate(staged: StagedAppImageUpdate): void {try {rmSync(staged.stagingDirectory, {recursive: true, force: true});} catch {}diff --git a/fluxer_desktop/src/main/AppStoreNativeBoundary.ts b/fluxer_desktop/src/main/AppStoreNativeBoundary.tsindex 5db03cd69..d0a9bb947 100644--- a/fluxer_desktop/src/main/AppStoreNativeBoundary.ts+++ b/fluxer_desktop/src/main/AppStoreNativeBoundary.ts@@ -1,6 +1,7 @@// SPDX-License-Identifier: AGPL-3.0-or-laterimport {createRequire} from 'node:module';+import {errorMessage} from '@electron/common/ErrorMessage';import type {AppStoreAccount,AppStoreAccountCompareAndSwapRequest,@@ -70,7 +71,7 @@ function describeAddonLoadFailure(error: unknown): string {if (error == null) {return 'the app store addon did not export a binding';}- const message = error instanceof Error ? error.message : String(error);+ const message = errorMessage(error);const reason = /^reason=(.+)$/mu.exec(message)?.[1]?.trim();const summary = (reason ?? message.split('\n')[0] ?? '').trim();if (summary.length === 0) {diff --git a/fluxer_desktop/src/main/MediaClipboard.ts b/fluxer_desktop/src/main/MediaClipboard.tsindex 7b83fe59b..cfe5b219c 100644--- a/fluxer_desktop/src/main/MediaClipboard.ts+++ b/fluxer_desktop/src/main/MediaClipboard.ts@@ -1,4 +1,5 @@import {isRecord} from '@fluxer/record_utils/src/RecordGuards';+// SPDX-License-Identifier: AGPL-3.0-or-laterimport crypto from 'node:crypto';@@ -7,6 +8,7 @@ import fs from 'node:fs/promises';import {createRequire} from 'node:module';import path from 'node:path';import {pathToFileURL} from 'node:url';+import {errorMessage} from '@electron/common/ErrorMessage';import {createChildLogger} from '@electron/common/Logger';import type {ClipboardWriteFileMediaType,@@ -60,7 +62,7 @@ function loadWinClipboardModule(): WinClipboardModule {} catch (error) {throw new Error(`@fluxer/win-clipboard failed to load on Windows — this is a packaging bug, not a runtime fallback case. ` +- `Original error: ${error instanceof Error ? error.message : String(error)}`,+ `Original error: ${errorMessage(error)}`,);}if (!mod.writeFileReferenceToClipboard) {diff --git a/fluxer_desktop/src/main/NativeAudio.ts b/fluxer_desktop/src/main/NativeAudio.tsindex f70e29d46..7c5c88bb0 100644--- a/fluxer_desktop/src/main/NativeAudio.ts+++ b/fluxer_desktop/src/main/NativeAudio.ts@@ -2,6 +2,7 @@import {randomUUID} from 'node:crypto';import {createRequire} from 'node:module';+import {errorMessage} from '@electron/common/ErrorMessage';import {createChildLogger} from '@electron/common/Logger';import type {NativeAudioApplication,@@ -258,9 +259,12 @@ function loadNativeAudioAddon(): NativeAddonLoadResult {const processSupported = backendInfo?.processSupported ?? processInclude;const systemSupported = backendInfo?.systemSupported ?? (processExclude || sessionMixer);const systemExcludesSelf = backendInfo?.systemExcludesSelf ?? (processExclude || sessionMixer);- const systemLoopbackMode =- backendInfo?.systemLoopbackMode ??- (processExclude ? 'process-exclude' : sessionMixer ? 'session-mixer' : 'unavailable');+ let systemLoopbackMode = backendInfo?.systemLoopbackMode;+ if (systemLoopbackMode == null && processExclude) {+ systemLoopbackMode = 'process-exclude';+ } else if (systemLoopbackMode == null) {+ systemLoopbackMode = sessionMixer ? 'session-mixer' : 'unavailable';+ }if (!processSupported && !systemSupported) {cachedLoadResult = {platform: process.platform,@@ -707,12 +711,12 @@ async function startNativeAudioCapture(const macCaptureScope =loadResult.platform === 'darwin' && options?.macCaptureScope === 'system' ? 'system' : 'process';const macSystemCapture = loadResult.platform === 'darwin' && macCaptureScope === 'system';- const winCaptureScope =- loadResult.platform === 'win32' && options?.winCaptureScope === 'session-mixer'- ? 'session-mixer'- : loadResult.platform === 'win32' && options?.winCaptureScope === 'system'- ? 'system'- : 'process';+ let winCaptureScope: 'process' | 'system' | 'session-mixer' = 'process';+ if (loadResult.platform === 'win32' && options?.winCaptureScope === 'session-mixer') {+ winCaptureScope = 'session-mixer';+ } else if (loadResult.platform === 'win32' && options?.winCaptureScope === 'system') {+ winCaptureScope = 'system';+ }const winSystemCapture =loadResult.platform === 'win32' && (winCaptureScope === 'system' || winCaptureScope === 'session-mixer');const winEndpoints = loadResult.platform === 'win32' ? options?.winEndpoints : undefined;@@ -738,14 +742,12 @@ async function startNativeAudioCapture(if (!availability.available) {throw new Error(`Native audio capture unavailable (${availability.reason ?? 'unknown'})`);}- const requestedScope: 'process' | 'system' =- winSystemCapture || macSystemCapture- ? 'system'- : linuxRule- ? linuxRule.include && linuxRule.include.length > 0- ? 'process'- : 'system'- : 'process';+ let requestedScope: 'process' | 'system' = 'process';+ if (winSystemCapture || macSystemCapture) {+ requestedScope = 'system';+ } else if (linuxRule && !(linuxRule.include && linuxRule.include.length > 0)) {+ requestedScope = 'system';+ }const capability = availability.capabilities?.[requestedScope];if (capability === false) {throw new Error(@@ -839,7 +841,7 @@ async function startNativeAudioCapture(}},onError: (error) => {- const detail = error instanceof Error ? error.message : String(error);+ const detail = errorMessage(error);logger.warn('Native audio capture emitted error', {captureId, error});stopActiveSession(session, 'addon-error', detail).catch((stopError) =>logger.warn('stopActiveSession failed after addon error', {captureId, error: stopError}),diff --git a/fluxer_desktop/src/main/NativeHardwareEncoder.ts b/fluxer_desktop/src/main/NativeHardwareEncoder.tsindex 18e617441..fa2272f3a 100644--- a/fluxer_desktop/src/main/NativeHardwareEncoder.ts+++ b/fluxer_desktop/src/main/NativeHardwareEncoder.ts@@ -1,6 +1,7 @@// SPDX-License-Identifier: AGPL-3.0-or-laterimport {createRequire} from 'node:module';+import {errorMessage} from '@electron/common/ErrorMessage';import {createChildLogger} from '@electron/common/Logger';import {VOICE_ENGINE_V2_HARDWARE_ENCODER_IPC_CHANNEL} from '@fluxer/voice_engine_v2/bridge';import {@@ -27,7 +28,7 @@ function loadHardwareEncoderModule(): HardwareEncoderModule | null {cachedModule = requireModule('@fluxer/hardware-encoder') as HardwareEncoderModule;} catch (error) {logger.warn('Failed to load @fluxer/hardware-encoder', error);- cachedModuleLoadErrorDetail = error instanceof Error ? error.message : String(error);+ cachedModuleLoadErrorDetail = errorMessage(error);cachedModule = null;}return cachedModule;@@ -45,7 +46,7 @@ function getHardwareEncoderCapabilities(): VoiceEngineV2HardwareEncoderCapabilitreturn normalizeVoiceEngineV2HardwareEncoderCapabilities(mod.getHardwareEncoderCapabilities());} catch (error) {logger.warn('Native hardware encoder getHardwareEncoderCapabilities() threw', error);- const detail = error instanceof Error ? error.message : String(error);+ const detail = errorMessage(error);return unavailableVoiceEngineV2HardwareEncoderCapabilities('query-failed', detail);}}diff --git a/fluxer_desktop/src/main/NativeModulePreflight.ts b/fluxer_desktop/src/main/NativeModulePreflight.tsindex e1690c730..910040980 100644--- a/fluxer_desktop/src/main/NativeModulePreflight.ts+++ b/fluxer_desktop/src/main/NativeModulePreflight.ts@@ -5,6 +5,7 @@ import {createHash} from 'node:crypto';import {existsSync, mkdirSync, readFileSync, writeFileSync} from 'node:fs';import {createRequire} from 'node:module';import path from 'node:path';+import {errorMessage} from '@electron/common/ErrorMessage';import NATIVE_MODULE_PREFLIGHT_MODULES from '@electron/main/NativeModulePreflightModules.json';import {app} from 'electron';import log from 'electron-log';@@ -208,7 +209,7 @@ function resolveSpecs(): {resolved: Array<ResolvedSpec>; failures: Array<NativeMfailures.push({name: spec.name,severity: spec.severity,- reason: `failed to resolve module: ${error instanceof Error ? error.message : String(error)}`,+ reason: `failed to resolve module: ${errorMessage(error)}`,});}}@@ -265,15 +266,17 @@ function probeAllModules(resolved: Array<ResolvedSpec>): ProbeOutcome {(_, j) => !(byIndex.get(j) ?? []).some((r) => r.phase === 'start'),);if (earlierMissing) continue;+ let reason = 'child process did not start probe';+ if (result.signal) {+ reason = `child process terminated by signal ${result.signal} before this probe ran`;+ } else if (result.status !== null && result.status !== 0) {+ reason = `child process exited with code ${result.status} before this probe ran`;+ }failures.push({name: spec.name,severity: spec.severity,modulePath,- reason: result.signal- ? `child process terminated by signal ${result.signal} before this probe ran`- : result.status !== null && result.status !== 0- ? `child process exited with code ${result.status} before this probe ran`- : 'child process did not start probe',+ reason,stdout: trimOutput(stdout),stderr: trimOutput(stderr),});diff --git a/fluxer_desktop/src/main/PlatformInfo.ts b/fluxer_desktop/src/main/PlatformInfo.tsindex 0e3ad4d29..471a0407c 100644--- a/fluxer_desktop/src/main/PlatformInfo.ts+++ b/fluxer_desktop/src/main/PlatformInfo.ts@@ -3,6 +3,7 @@import {createRequire} from 'node:module';import os from 'node:os';import {BUILD_CHANNEL} from '@electron/common/BuildChannel';+import {errorMessage} from '@electron/common/ErrorMessage';import type {AppMetricsSnapshot,CpuInfo,@@ -20,7 +21,6 @@ const requireModule = createRequire(import.meta.url);type MacSysctlModule = {sysctlByNameInt: ((name: string) => Promise<number | null>) | null;- sysctlByNameString: ((name: string) => Promise<string | null>) | null;loadError: Error | null;};type NativeGpuInfoSource = 'metal' | 'dxgi' | 'linux-sysfs';@@ -88,9 +88,9 @@ function loadMacSysctl(): MacSysctlModule | null {macSysctlCache = requireModule('@fluxer/mac-sysctl') as MacSysctlModule;} catch (error) {throw new Error(- `@fluxer/mac-sysctl failed to load on macOS; native diagnostics cannot continue. Original error: ${- error instanceof Error ? error.message : String(error)- }`,+ `@fluxer/mac-sysctl failed to load on macOS; native diagnostics cannot continue. Original error: ${errorMessage(+ error,+ )}`,);}return macSysctlCache;