{"record":{"id":"14e65e5c89163e5f","repo":"moeru-ai/airi","slug":"invalid-remote-debug-port-env-app-remote-debug","errorCode":null,"errorMessage":"Invalid remote debug port: ${env.APP_REMOTE_DEBUG_PORT}","messagePattern":"Invalid remote debug port: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/stage-tamagotchi/src/main/app/debugger.ts","lineNumber":12,"sourceCode":"import http from 'node:http'\n\nimport { env } from 'node:process'\n\nimport { app, shell } from 'electron'\n\n/** Enables Electron's CDP endpoint before the app ready event. */\nexport function setupDebugger() {\n  if (/^true$/i.test(env.APP_REMOTE_DEBUG || '')) {\n    const remoteDebugPort = Number(env.APP_REMOTE_DEBUG_PORT || '9222')\n    if (Number.isNaN(remoteDebugPort) || !Number.isInteger(remoteDebugPort) || remoteDebugPort < 0 || remoteDebugPort > 65535) {\n      throw new Error(`Invalid remote debug port: ${env.APP_REMOTE_DEBUG_PORT}`)\n    }\n\n    app.commandLine.appendSwitch('remote-debugging-port', String(remoteDebugPort))\n    app.commandLine.appendSwitch('remote-allow-origins', `http://localhost:${remoteDebugPort}`)\n  }\n}\n\n/**\n * Opens the inspector for the first available Electron renderer target.\n *\n * Developers may keep CDP enabled without opening the system browser by\n * setting `APP_REMOTE_DEBUG_NO_OPEN=true`.\n */\nexport function openDebugger() {\n  if (/^true$/i.test(env.APP_REMOTE_DEBUG || '')) {\n    const remoteDebugEndpoint = `http://localhost:${env.APP_REMOTE_DEBUG_PORT || '9222'}`\n\n    http.get(`${remoteDebugEndpoint}/json`, (res) => {","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/apps/stage-tamagotchi/src/main/app/debugger.ts#L1-L30","documentation":"Thrown by setupDebugger in the Electron main process when APP_REMOTE_DEBUG is truthy but APP_REMOTE_DEBUG_PORT cannot be parsed as a valid integer port (0–65535). The validator uses Number(env.APP_REMOTE_DEBUG_PORT || '9222'), so an empty value falls back to 9222 safely; the throw only happens for a non-empty, malformed, or out-of-range value.","triggerScenarios":"Launching the Electron app with APP_REMOTE_DEBUG=true and APP_REMOTE_DEBUG_PORT set to a non-numeric string (e.g. 'abc'), a float (e.g. '9222.5'), a negative number, or a value above 65535.","commonSituations":"Typo in an .env or launch config; copy-pasting a port string with a colon; setting a port already expressed as a URL fragment; CI matrix setting an out-of-range port variable.","solutions":["Set APP_REMOTE_DEBUG_PORT to an integer between 0 and 65535 (commonly 9222).","Omit APP_REMOTE_DEBUG_PORT entirely to accept the 9222 default.","If you do not need remote debugging, leave APP_REMOTE_DEBUG unset/false so the validator never runs.","Check the launch profile / package.json script that sets the env var for stray characters."],"exampleFix":"// before\nAPP_REMOTE_DEBUG=true APP_REMOTE_DEBUG_PORT=92:22 electron .\n\n// after\nAPP_REMOTE_DEBUG=true APP_REMOTE_DEBUG_PORT=9222 electron .","handlingStrategy":"validation","validationCode":"function parseDebugPort(raw: string | undefined): number | null {\n  const port = Number(raw || '9222')\n  if (Number.isNaN(port) || !Number.isInteger(port) || port < 0 || port > 65535) return null\n  return port\n}\n\nif (parseDebugPort(env.APP_REMOTE_DEBUG_PORT) === null) {\n  // fail with a clear message before Electron app construction\n}","typeGuard":"function isValidPort(raw: string | undefined): boolean {\n  const port = Number(raw || '9222')\n  return Number.isInteger(port) && port >= 0 && port <= 65535\n}","tryCatchPattern":null,"preventionTips":["Keep APP_REMOTE_DEBUG_PORT as a plain integer in env files.","Omit the variable to use the 9222 default.","Lint CI env files for numeric port values."],"tags":["electron","configuration","environment-variables","debugging","startup"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}