{"record":{"id":"944e906cd5f0a274","repo":"paperclipai/paperclip","slug":"choose-a-company-before-connecting","errorCode":null,"errorMessage":"Choose a company before connecting.","messagePattern":"Choose a company before connecting\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ui/src/components/ai-connections/useLocalAiLogin.ts","lineNumber":87,"sourceCode":"    return () => {\n      cancelled = true;\n      clearTimeout(timer);\n      window.removeEventListener(\"focus\", onFocus);\n      document.removeEventListener(\"visibilitychange\", onFocus);\n      // Navigation is not cancellation. The server resumes this bounded attempt\n      // when the user returns and reaps abandoned attempts after expiry. Deleting\n      // here made copied CODEX_HOME commands point at nonexistent directories.\n    };\n  }, [companyId, active, isolated, target, generation]);\n  return {\n    isolated,\n    command: attempt?.command,\n    status,\n    preparing: active && !status && !error,\n    error,\n    retry: () => { restartRequested.current = true; cancelCurrent(); setGeneration((value) => value + 1); },\n    connect: (input = intent) => {\n      if (!companyId) throw new Error(\"Choose a company before connecting.\");\n      if (isolated && !attempt) throw new Error(\"Prepare local sign-in before connecting.\");\n      return aiConnectionsApi.connectLocal(companyId, { ...input, ...(attempt ? { localSessionId: attempt.sessionId } : {}) });\n    },\n  };\n}\n","sourceCodeStart":69,"sourceCodeEnd":93,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/ui/src/components/ai-connections/useLocalAiLogin.ts#L69-L93","documentation":"useLocalAiLogin's `connect()` requires a selected company because the connect call `aiConnectionsApi.connectLocal(companyId, ...)` is company-scoped. If `companyId` is falsy when the user clicks connect, it throws this guard error immediately instead of issuing a request that would 400/404.","triggerScenarios":"Calling `connect()` (or `localLogin`/`login` wrappers) from the AI-connections UI before the user picked a company, e.g. on a page without company context or before company selection loads.","commonSituations":"Deep-linking straight to the AI connections connect dialog without `?company=` context; company query still loading (undefined) while the connect button is enabled; company selector cleared.","solutions":["Require company selection before rendering/enabling the connect button (disable until `companyId` is truthy).","Ensure the page is wrapped in the company-selection context provider so companyId resolves.","Guard call sites: `if (!companyId) { openCompanyPicker(); return; }` before calling connect."],"exampleFix":"// before\n<button onClick={() => connect()}>Connect</button>\n// after\n<button disabled={!companyId} onClick={() => companyId && connect()}>Connect</button>","handlingStrategy":"validation","validationCode":"if (!companyId) { openCompanyPicker(); return; }","typeGuard":"const hasCompany = (id: string | null | undefined): id is string => typeof id === 'string' && id.length > 0;","tryCatchPattern":"try { await connect(); } catch (e) { if (/Choose a company/.test(e.message)) openCompanyPicker(); }","preventionTips":["Disable connect until companyId resolves.","Ensure the route is inside the company selection context.","Guard deep links that bypass company selection."],"tags":["react","company-scope","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"3f1d897a7c018d76563a21c6e39c3c9b03933622","analyzedAt":"2026-09-18T08:03:59.046Z","contentChangedAt":"2026-09-18T08:03:59.046Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}