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

  1. Require company selection before rendering/enabling the connect button (disable until `companyId` is truthy).
  2. Ensure the page is wrapped in the company-selection context provider so companyId resolves.
  3. 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

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


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)