{"record":{"id":"ea65ef83c33d4d81","repo":"coder/code-server","slug":"cannot-open-socket-paths","errorCode":null,"errorMessage":"Cannot open socket paths","messagePattern":"Cannot open socket paths","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/node/util.ts","lineNumber":428,"sourceCode":"  if (platform === \"win32\" || platform === \"wsl\") {\n    command = platform === \"wsl\" ? \"cmd.exe\" : \"cmd\"\n    args.push(\"/c\", \"start\", '\"\"', \"/b\")\n    urlSearch = urlSearch.replace(/&/g, \"^&\")\n  }\n\n  return {\n    args,\n    command,\n    urlSearch,\n  }\n}\n\n/**\n * Try opening an address using whatever the system has set for opening URLs.\n */\nexport const open = async (address: URL | string): Promise<void> => {\n  if (typeof address === \"string\") {\n    throw new Error(\"Cannot open socket paths\")\n  }\n  // Web sockets do not seem to work if browsing with 0.0.0.0.\n  const url = new URL(address)\n  if (url.hostname === \"0.0.0.0\") {\n    url.hostname = \"localhost\"\n  }\n  const platform = (await isWsl(process.platform, os.release(), \"/proc/version\")) ? \"wsl\" : process.platform\n  const { command, args, urlSearch } = constructOpenOptions(platform, url.search)\n  url.search = urlSearch\n  const proc = cp.spawn(command, [...args, url.toString()], {})\n  await new Promise<void>((resolve, reject) => {\n    proc.on(\"error\", reject)\n    proc.on(\"close\", (code) => {\n      return code !== 0 ? reject(new Error(`Failed to open with code ${code}`)) : resolve()\n    })\n  })\n}\n","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/coder/code-server/blob/51f90a376b42e217b38937410fe2855e0c1db87e/src/node/util.ts#L410-L446","documentation":"Thrown by the open() helper in src/node/util.ts when it receives a plain string instead of a URL object. The function intentionally rejects strings because in code-server a string address is assumed to be a Unix socket path, which cannot be opened by a browser/xdg-open/cmd. The fix is to pass a URL instance so new URL(address) succeeds.","triggerScenarios":"Calling open(someString) where someString is a socket path (e.g. '/run/code-server/socket') rather than an http(s) URL. This is the 'open in browser' code path used after server start; passing a socket-path string is treated as a programming error.","commonSituations":"A code path that resolved the listen address to a socket path string and forwarded it to open(); a refactor that changed the address type from URL to string; misconfigured --socket / SOCKET_PATH combined with the auto-open-browser feature.","solutions":["Pass a URL object to open(): open(new URL('http://localhost:8080')).","If you intended to use a socket path, do not call open() on it — disable the auto-open-browser behavior (set --open=false / do not pass --open).","Separate the listen address (which may be a socket) from the browser-open address (which must be an http(s) URL).","Check the caller that constructs the address and ensure it builds a URL when opening is desired."],"exampleFix":"// before\nopen(serverAddress) // serverAddress is a socket-path string\n// after\nopen(new URL(`http://localhost:${port}`))","handlingStrategy":"type-guard","validationCode":"// Only call open() with a real http(s) URL.\nimport { open } from '../util'\nif (address instanceof URL && /^https?:$/.test(address.protocol)) {\n  await open(address)\n}","typeGuard":"function isOpenableUrl(addr: unknown): addr is URL {\n  return addr instanceof URL && /^https?:$/.test(addr.protocol)\n}","tryCatchPattern":"try {\n  await open(maybeAddress)\n} catch (e) {\n  if (e.message === 'Cannot open socket paths') {\n    // address was a socket-path string; skip auto-open\n  } else throw e\n}","preventionTips":["Never pass socket-path strings to open().","Construct a URL from the configured host/port before opening.","Disable --open when running with --socket.","Keep the listen-address type distinct from the open-browser address type."],"tags":["open-browser","socket","validation","util"],"backgroundTag":null,"analyzedSha":"51f90a376b42e217b38937410fe2855e0c1db87e","analyzedAt":"2026-08-12T11:27:34.273Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}