paperclipai/paperclip · error · Error
Choose a company before connecting.
Error message
Choose a company before connecting.
What it means
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.
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.
Example fix
// before
<button onClick={() => connect()}>Connect</button>
// after
<button disabled={!companyId} onClick={() => companyId && connect()}>Connect</button> Defensive patterns
Strategy: validation
Validate before calling
if (!companyId) { openCompanyPicker(); return; } Type guard
const hasCompany = (id: string | null | undefined): id is string => typeof id === 'string' && id.length > 0;
Try / catch
try { await connect(); } catch (e) { if (/Choose a company/.test(e.message)) openCompanyPicker(); } Prevention
- Disable connect until companyId resolves.
- Ensure the route is inside the company selection context.
- Guard deep links that bypass company selection.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Select an organization to test adapter environment
- The named reviewer is not available in this company. Choose…
- A full lowercase source SHA is required.
- A reusable lease cannot be replaced and reacquired in the…
- A reusable lease handoff requires an execution workspace…
AI-assisted analysis of paperclipai/paperclip@3f1d897a7c (2026-09-18).
Data as JSON: /api/errors/944e906cd5f0a274.
Report an issue: GitHub.
Appendix: source
Thrown at ui/src/components/ai-connections/useLocalAiLogin.ts:87
return () => {
cancelled = true;
clearTimeout(timer);
window.removeEventListener("focus", onFocus);
document.removeEventListener("visibilitychange", onFocus);
// Navigation is not cancellation. The server resumes this bounded attempt
// when the user returns and reaps abandoned attempts after expiry. Deleting
// here made copied CODEX_HOME commands point at nonexistent directories.
};
}, [companyId, active, isolated, target, generation]);
return {
isolated,
command: attempt?.command,
status,
preparing: active && !status && !error,
error,
retry: () => { restartRequested.current = true; cancelCurrent(); setGeneration((value) => value + 1); },
connect: (input = intent) => {
if (!companyId) throw new Error("Choose a company before connecting.");
if (isolated && !attempt) throw new Error("Prepare local sign-in before connecting.");
return aiConnectionsApi.connectLocal(companyId, { ...input, ...(attempt ? { localSessionId: attempt.sessionId } : {}) });
},
};
}
View on GitHub (pinned to 3f1d897a7c)