{"record":{"id":"aaa235ccd1063520","repo":"musistudio/claude-code-router","slug":"invalid-proxy-endpoint-endpoint","errorCode":null,"errorMessage":"Invalid proxy endpoint: ${endpoint}","messagePattern":"Invalid proxy endpoint: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/proxy/system-proxy.ts","lineNumber":322,"sourceCode":"}\n\nexport async function readCurrentSystemUpstreamProxy(managedEndpointUrl: string): Promise<UpstreamProxyConfig | undefined> {\n  if (process.platform !== \"darwin\" && process.platform !== \"win32\") {\n    return undefined;\n  }\n\n  const managedEndpoint = parseManagedEndpoint(managedEndpointUrl);\n  const snapshot = process.platform === \"win32\"\n    ? await captureWindowsSystemProxySnapshot(managedEndpoint)\n    : await captureMacSystemProxySnapshot(managedEndpoint);\n  return readSnapshotUpstreamProxy(snapshot, managedEndpoint);\n}\n\nfunction parseManagedEndpoint(endpoint: string): ManagedProxyEndpoint {\n  const parsed = new URL(endpoint);\n  const port = Number(parsed.port || (parsed.protocol === \"https:\" ? 443 : 80));\n  if (!parsed.hostname || !Number.isInteger(port) || port < 1 || port > 65535) {\n    throw new Error(`Invalid proxy endpoint: ${endpoint}`);\n  }\n  return {\n    host: parsed.hostname,\n    port,\n    url: `http://${formatProxyHost(parsed.hostname)}:${port}`\n  };\n}\n\nfunction normalizeCustomProxyServer(server: string): string {\n  const trimmed = server.trim();\n  if (!trimmed) {\n    return \"\";\n  }\n\n  try {\n    const parsed = new URL(/^[a-z][a-z0-9+.-]*:\\/\\//i.test(trimmed) ? trimmed : `http://${trimmed}`);\n    return parsed.hostname;\n  } catch {","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/proxy/system-proxy.ts#L304-L340","documentation":"The system-proxy module could not parse a previously persisted managed proxy endpoint string (from its state file/restore data). The value must be a valid URL with a hostname and integer port between 1 and 65535; otherwise restore()/managedEndpoint() throws.","triggerScenarios":"Calling restore() or reading the managed endpoint when the saved endpoint string is corrupt — e.g. 'http://:0', 'not a url', a port of NaN, or a hand-edited state file.","commonSituations":"Corrupted or manually edited proxy state file after a crash; version changes that altered the endpoint format; leftover state from a different tool; empty-string endpoint persisted by an older buggy version.","solutions":["Delete/reset the persisted proxy state file so a fresh endpoint is created","Inspect the stored endpoint string and fix or regenerate it via the module's API instead of editing state by hand","Catch the error during restore and fall back to a clean managed endpoint setup"],"exampleFix":"// before\nawait systemProxy.restore(); // throws on corrupt state\n\n// after\ntry {\n  await systemProxy.restore();\n} catch {\n  await systemProxy.clearState(); // or delete the state file\n  await systemProxy.restore();\n}","handlingStrategy":"try-catch","validationCode":"function isValidEndpoint(endpoint: string): boolean {\n  try { const u = new URL(endpoint); const p = Number(u.port || 80); return !!u.hostname && Number.isInteger(p) && p >= 1 && p <= 65535; } catch { return false; }\n}","typeGuard":"function isManagedEndpointValue(v: unknown): v is string { return typeof v === \"string\" && isValidEndpoint(v); }","tryCatchPattern":"try { await systemProxy.restore(); } catch (e) { if (e.message.startsWith(\"Invalid proxy endpoint\")) { await systemProxy.reset(); await systemProxy.restore(); return; } throw e; }","preventionTips":["Never hand-edit persisted proxy state","Validate state file contents before restore","Keep a recovery path that resets state on parse failure"],"tags":["system-proxy","state","parsing","restore","configuration"],"backgroundTag":"corrupted-config-state","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}