{"record":{"id":"98fbd1310ae6a0fa","repo":"moeru-ai/airi","slug":"mutexacquiretimeout-must-be-a-positive-finite-numb","errorCode":null,"errorMessage":"mutexAcquireTimeout must be a positive finite number","messagePattern":"mutexAcquireTimeout must be a positive finite number","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/electron-screen-capture/src/main/index.ts","lineNumber":113,"sourceCode":"let screenCaptureSourceMutexHandle: string | undefined\nlet setSourceMutexTimeoutHandle: NodeJS.Timeout | undefined\n\nexport function initScreenCaptureForMain(options: InitMainOptions = {}): void {\n  const {\n    forceCoreAudioTap = false,\n    mutexAcquireTimeout = 5000,\n  } = options\n\n  let log = useLogg('screen-capture').useGlobalConfig()\n  if (options?.loggerOptions?.logLevel) {\n    log = log.withLogLevelString((options?.loggerOptions?.logLevel ?? 'info') as LogLevelString)\n  }\n  if (options?.loggerOptions?.format) {\n    log = log.withFormat((options?.loggerOptions?.format ?? 'plain') as Format)\n  }\n\n  if (mutexAcquireTimeout <= 0 || !Number.isFinite(mutexAcquireTimeout) || Number.isNaN(mutexAcquireTimeout)) {\n    throw new Error('mutexAcquireTimeout must be a positive finite number')\n  }\n\n  if (initMainCalled) {\n    log.warn('initScreenCaptureForMain should only be called once')\n    return\n  }\n  initMainCalled = true\n  setSourceMutex = withTimeout(new Mutex(), mutexAcquireTimeout)\n\n  // Get other enabled features from the command line.\n  const otherEnabledFeatures = app.commandLine.getSwitchValue(featureSwitchKey)?.split(',')\n\n  // Remove the switch if it exists.\n  if (app.commandLine.hasSwitch(featureSwitchKey)) {\n    app.commandLine.removeSwitch(featureSwitchKey)\n  }\n\n  // Add the feature flags to the command line with any other user-enabled features concatenated.","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/electron-screen-capture/src/main/index.ts#L95-L131","documentation":"initScreenCaptureForMain validates the mutexAcquireTimeout option (default 5000 ms) up front: it must be > 0, finite, and not NaN, because it is passed to withTimeout(new Mutex(), ...) to bound source-mutex acquisition. Any invalid custom value throws immediately during Electron main-process setup.","triggerScenarios":"Passing mutexAcquireTimeout: 0, a negative number, Infinity, or NaN — classically Number(undefinedEnvVar) or parseInt of an unset/blank config value.","commonSituations":"Timeout sourced from an environment variable or config file that is unset on another machine; a 'disable timeout' attempt passing 0; copy-pasted config with an empty string coerced to 0.","solutions":["Pass a positive finite millisecond value, or omit the option to keep the 5000 ms default","Sanitize env/config-derived numbers: Number.isFinite(t) && t > 0 before forwarding","If you intended 'no timeout', keep a large finite value instead of Infinity — the API deliberately rejects it"],"exampleFix":"// before\ninitScreenCaptureForMain({ mutexAcquireTimeout: Number(process.env.SCREEN_CAP_TIMEOUT) }) // NaN when unset\n\n// after\nconst t = Number(process.env.SCREEN_CAP_TIMEOUT)\ninitScreenCaptureForMain({ mutexAcquireTimeout: Number.isFinite(t) && t > 0 ? t : 5000 })","handlingStrategy":"validation","validationCode":"const t = options.mutexAcquireTimeout ?? 5000\nif (!(typeof t === 'number' && t > 0 && Number.isFinite(t)))\n  throw new Error('mutexAcquireTimeout must be a positive finite number (ms)')\nawait initScreenCaptureForMain({ ...options, mutexAcquireTimeout: t })","typeGuard":"function isPositiveFinite(v: unknown): v is number {\n  return typeof v === 'number' && v > 0 && Number.isFinite(v)\n}","tryCatchPattern":null,"preventionTips":["Sanitize env/config-derived numbers with Number.isFinite before forwarding","Document that 0/Infinity mean 'reject', not 'disable the timeout'","Omit the option to accept the 5000 ms default"],"tags":["electron","options","validation","initialization"],"backgroundTag":"invalid-enum-value","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}