{"record":{"id":"7005fedd71edefbe","repo":"microsoft/autogen","slug":"invalid-server-url-configuration-7005fe","errorCode":null,"errorMessage":"Invalid server URL configuration","messagePattern":"Invalid server URL configuration","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx","lineNumber":546,"sourceCode":"\n    return socket;\n  };\n\n  // Helper for WebSocket URL\n  const getBaseUrl = (url: string): string => {\n    try {\n      let baseUrl = url.replace(/(^\\w+:|^)\\/\\//, \"\");\n      if (baseUrl.startsWith(\"localhost\")) {\n        baseUrl = baseUrl.replace(\"/api\", \"\");\n      } else if (baseUrl === \"/api\") {\n        baseUrl = window.location.host;\n      } else {\n        baseUrl = baseUrl.replace(\"/api\", \"\").replace(/\\/$/, \"\");\n      }\n      return baseUrl;\n    } catch (error) {\n      console.error(\"Error processing server URL:\", error);\n      throw new Error(\"Invalid server URL configuration\");\n    }\n  };\n\n  return (\n    <div className=\"text-primary h-[calc(100vh-165px)] bg-primary relative rounded flex-1 scroll\">\n      {contextHolder}\n      <div className=\"flex pt-2 items-center justify-between text-sm h-10\">\n        <div className=\"flex items-center gap-2 min-w-0 overflow-hidden flex-1 pr-4\">\n          {isCompareMode ? (\n            <SessionDropdown\n              session={session}\n              availableSessions={availableSessions}\n              onSessionChange={onSessionChange || (() => {})}\n              className=\"w-full\"\n            />\n          ) : (\n            <>\n              <span className=\"text-primary font-medium whitespace-nowrap flex-shrink-0\">","sourceCodeStart":528,"sourceCodeEnd":564,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx#L528-L564","documentation":"Error thrown by getBaseUrl in autogen-studio's playground chat when normalizing the configured server URL fails inside the try block. The function strips protocols, handles 'localhost' and '/api' special cases, and re-raises any unexpected failure as this generic configuration error, so the WebSocket URL cannot be built.","triggerScenarios":"Practically hard to trigger because String.prototype.replace does not throw on ordinary inputs; it fires only if url or window.location is unexpectedly null/undefined (e.g. url passed as null from config, or the code runs outside a browser during SSR/test where window is undefined and the catch converts the ReferenceError).","commonSituations":"Server URL setting left blank or saved as null in the UI settings; importing the chat component in a Node test environment where window is undefined; corrupted localStorage settings after a version change renamed the config key.","solutions":["Validate the serverUrl setting before use: default it to window.location.host when empty or null.","Guard non-browser environments: only build the WS URL when typeof window !== \"undefined\".","Clear/re-save the server URL setting in the UI if it was persisted in an old format."],"exampleFix":"// before\nconst wsUrl = `${wsProtocol}//${getBaseUrl(serverUrl)}/api/ws/runs/${runId}`;\n\n// after\nconst base = serverUrl || window.location.host;\nconst wsUrl = `${wsProtocol}//${getBaseUrl(base)}/api/ws/runs/${runId}`;","handlingStrategy":"validation","validationCode":"if (typeof window === \"undefined\" || !window.location?.host) {\n  throw new Error(\"getBaseUrl requires a browser environment\");\n}\nconst normalizedUrl = serverUrl?.trim() || window.location.host;\nconst base = getBaseUrl(normalizedUrl);","typeGuard":"const isValidServerUrl = (u: unknown): u is string =>\n  typeof u === \"string\" && u.trim().length > 0;","tryCatchPattern":"try { const base = getBaseUrl(serverUrl); }\ncatch (e) {\n  if (e instanceof Error && e.message === \"Invalid server URL configuration\") {\n    const fallback = window.location.host;\n    return getBaseUrl(fallback);\n  }\n  throw e;\n}","preventionTips":["Default empty serverUrl to window.location.host before calling getBaseUrl.","Never persist null as the server URL setting; coerce blank inputs on save.","Skip WebSocket setup during SSR by guarding on typeof window."],"tags":["react","typescript","configuration","frontend"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}