{"record":{"id":"b1d8b6d771e3bd88","repo":"garrytan/gstack","slug":"server-port-not-available","errorCode":null,"errorMessage":"Server port not available","messagePattern":"Server port not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/write-commands.ts","lineNumber":744,"sourceCode":"        const { domains } = listDomains(browser, profile);\n        const allDomainNames = domains.map((d: any) => d.domain);\n        if (allDomainNames.length === 0) {\n          return `No cookies found in ${browser} (profile: ${profile})`;\n        }\n        const result = await importCookies(browser, allDomainNames, profile);\n        if (result.cookies.length > 0) {\n          await page.context().addCookies(result.cookies);\n          bm.trackCookieImportDomains(allDomainNames);\n        }\n        const msg = [`Imported ${result.count} cookies across ${Object.keys(result.domainCounts).length} domains from ${browser}`];\n        msg.push('(used --all: all browser cookies imported, consider --domain for tighter scoping)');\n        if (result.failed > 0) msg.push(`(${result.failed} failed to decrypt)`);\n        return msg.join(' ');\n      }\n\n      // Picker UI mode — open in user's browser for interactive domain selection\n      const port = bm.serverPort;\n      if (!port) throw new Error('Server port not available');\n\n      const browsers = findInstalledBrowsers();\n      if (browsers.length === 0) {\n        throw new Error(`No Chromium browsers found. Supported: ${listSupportedBrowserNames().join(', ')}`);\n      }\n\n      const code = generatePickerCode();\n      const pickerUrl = `http://127.0.0.1:${port}/cookie-picker?code=${code}`;\n      try {\n        Bun.spawn(['open', pickerUrl], { stdout: 'ignore', stderr: 'ignore' });\n      } catch (err: any) {\n        // open may fail on non-macOS or if 'open' binary is missing — URL is in the message below\n        if (err?.code !== 'ENOENT' && !err?.message?.includes('spawn')) throw err;\n      }\n\n      return `Cookie picker opened at http://127.0.0.1:${port}/cookie-picker\\nDetected browsers: ${browsers.map(b => b.name).join(', ')}\\nSelect domains to import, then close the picker when done.\\n\\nTip: For scripted imports, use --domain <domain> to scope cookies to a single domain.`;\n    }\n","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/write-commands.ts#L726-L762","documentation":"Thrown by `browse cookie-import-browser` in picker-UI mode (no `--domain` and no `--all`) when `bm.serverPort` is falsy (0). The picker UI is served as an HTTP page at `http://127.0.0.1:${port}/cookie-picker`, so without a known port the command cannot construct the URL or open the picker. `serverPort` defaults to 0 and is set by the server bootstrap (`browserManager.serverPort = port`) when the HTTP listener starts.","triggerScenarios":"Running the picker-mode command before the browse HTTP server has bound its port; the server failed to start but the command layer is still reachable; an embedded usage where the BrowserManager is instantiated without the server lifecycle.","commonSituations":"An SDK user constructs a BrowserManager directly for automation and never starts the HTTP server, then calls the picker command; the server port binding failed silently (EADDRINUSE) and serverPort stayed 0; a test harness invokes write commands without the full server bootstrap.","solutions":["Ensure the browse HTTP server is started before invoking picker mode — `serverPort` is set during server bootstrap.","Use direct mode (`--domain <domain>`) or `--all` instead of the picker; neither requires the HTTP server.","Check `bm.serverPort` is non-zero before dispatching the picker command.","If the server should be running, diagnose why the port binding failed (check for EADDRINUSE, permissions, or a crashed server task)."],"exampleFix":"// before (no HTTP server running)\nawait runBrowseCommand(['cookie-import-browser']);\n\n// after\nawait runBrowseCommand(['cookie-import-browser', 'comet', '--domain', 'target.com']);\n// or ensure the server is bootstrapped so bm.serverPort is set","handlingStrategy":"validation","validationCode":"function ensurePickerReady(serverPort: number): void {\n  if (!serverPort) {\n    throw new Error('cookie picker requires the HTTP server to be running (serverPort is 0)');\n  }\n}","typeGuard":"function isServerPortConfigured(port: number): boolean {\n  return typeof port === 'number' && port > 0;\n}","tryCatchPattern":null,"preventionTips":["Start the browse HTTP server before invoking picker mode.","Use --domain or --all modes which do not require the HTTP server.","Check bm.serverPort is non-zero before dispatching the picker command."],"tags":["server","cookies","import","configuration","browser-import","browse-command"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}