{"record":{"id":"d9cdad90a522d67c","repo":"stablyai/orca","slug":"invalid-active-server-preference","errorCode":null,"errorMessage":"Invalid Active Server preference","messagePattern":"Invalid Active Server preference","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ipc/settings.ts","lineNumber":286,"sourceCode":"      if (typeof afterValue !== 'boolean') {\n        // No non-bool whitelist entries today; skip rather than guess.\n        continue\n      }\n      track('settings_changed', {\n        setting_key: key as SettingsChangedKey,\n        value_kind: 'bool'\n      })\n    }\n\n    return result\n  })\n\n  ipcMain.handle(\n    'settings:set-active-runtime-environment-preference',\n    (event, args: { environmentId?: unknown }): GlobalSettings => {\n      const requestedEnvironmentId = args?.environmentId\n      if (requestedEnvironmentId !== null && typeof requestedEnvironmentId !== 'string') {\n        throw new Error('Invalid Active Server preference')\n      }\n      const requestedId = requestedEnvironmentId?.trim() || null\n      const environmentId =\n        requestedId === null ? null : resolveEnvironment(app.getPath('userData'), requestedId).id\n      return store.updateSettings(\n        { activeRuntimeEnvironmentId: environmentId },\n        { notifyListeners: true, originWebContentsId: event.sender.id }\n      )\n    }\n  )\n\n  ipcMain.handle('settings:listFonts', () => {\n    return listSystemFontFamilies()\n  })\n\n  ipcMain.handle('settings:previewGhosttyImport', () => {\n    return previewGhosttyImport(store)\n  })","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/settings.ts#L268-L304","documentation":"Thrown by the settings:set-active-runtime-environment-preference handler when args.environmentId is neither null nor a string. The handler then trims a string value and resolves it via resolveEnvironment, so the type check is the first guard against malformed IPC input (e.g. a number, object, or undefined payload shape).","triggerScenarios":"Invoking the IPC with environmentId as a number (e.g. 0), an object, an array, or boolean. Also when undefined is passed where the renderer intended null (note: undefined passes the check because the guard only rejects non-null non-string values — undefined is not null and not a string, so it is rejected).","commonSituations":"Renderer bug sending the raw value of an uncontrolled input; a serialization layer that drops null to undefined; a typed caller that widened the field to unknown without narrowing.","solutions":["Always send environmentId as either a string id or explicitly null — never undefined or other types.","Type the IPC call site narrowly (environmentId: string | null) and lint against unknown.","In the renderer, coerce: const id = value == null ? null : String(value).","Add a runtime guard in the renderer that blocks non-string/non-null before invoking."],"exampleFix":"// before\nipc.invoke('settings:set-active-runtime-environment-preference', { environmentId: selected })\n\n// after\nconst environmentId = selected == null ? null : typeof selected === 'string' ? selected : null\nipc.invoke('settings:set-active-runtime-environment-preference', { environmentId })","handlingStrategy":"type-guard","validationCode":"function coerceActiveServerPreference(value: unknown): string | null {\n  if (value === null) return null\n  if (typeof value === 'string') return value\n  return null // refuse undefined/numbers/objects\n}\n\nconst environmentId = coerceActiveServerPreference(selected)\nawait ipc.invoke('settings:set-active-runtime-environment-preference', { environmentId })","typeGuard":"function isNullableStringId(value: unknown): value is string | null {\n  return value === null || typeof value === 'string'\n}","tryCatchPattern":"try {\n  await ipc.invoke('settings:set-active-runtime-environment-preference', { environmentId })\n} catch (e) {\n  if (/Invalid Active Server/.test((e as Error).message)) {\n    showError('Pick a server from the list, or clear the selection.')\n  } else throw e\n}","preventionTips":["Type the field as string | null at the call site, never unknown or undefined.","Coerce undefined to null before sending.","Let the user pick from a resolved list rather than typing free text."],"tags":["ipc","settings","runtime-environment","validation","type-error"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}