ComposioHQ/composio · error · Error

Pusher client not initialized

Error message

Pusher client not initialized

What it means

triggerSubscribe requires the realtime Pusher client to already be initialized (via getPusherClient). Calling it before getPusherClient has completed throws this guard error because PusherUtils.pusherClient is undefined.

Source

Thrown at ts/packages/core/src/utils/pusher.ts:235

    }
  }

  /**
   * Subscribes to a trigger channel for a client and handles chunked data.
   * @param {string} clientId - The unique identifier for the client subscribing to the events.
   * @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
   *
   * @example
   * ```ts
   * composio.trigger.subscribe((data) => {
   *   console.log(data);
   * });
   * ```
   */
  static triggerSubscribe(clientId: string, fn: (data: TriggerData) => void): void {
    try {
      if (!PusherUtils.pusherClient) {
        throw new Error('Pusher client not initialized');
      }

      const channel = PusherUtils.pusherClient.subscribe(`private-${clientId}_triggers`);

      // Add subscription error handling
      channel.bind('pusher:subscription_error', (data: Record<string, unknown>) => {
        const error = data.error ? String(data.error) : 'Unknown subscription error';
        throw new PusherSubscriptionError(`Trigger subscription error`, {
          cause: error,
        });
      });

      // Wrap the callback to handle errors
      const safeCallback = (data: TriggerData) => {
        try {
          fn(data);
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : String(error);

View on GitHub (pinned to 64b1b85502)

Solutions

  1. Await getPusherClient(baseURL, apiKey) before calling triggerSubscribe
  2. Check PusherUtils.pusherClient (or the public SDK accessor) is set before subscribing
  3. Ensure initialization isn't swallowed by an earlier try/catch that ate the init error

Example fix

// before
PusherUtils.triggerSubscribe(clientId, fn);

// after
await PusherUtils.getPusherClient(baseURL, apiKey);
PusherUtils.triggerSubscribe(clientId, fn);
Defensive patterns

Strategy: validation

Validate before calling

await PusherUtils.getPusherClient(baseURL, apiKey); // must complete first
if (!PusherUtils.pusherClient) throw new Error('init required');

Try / catch

try {
  PusherUtils.triggerSubscribe(clientId, fn);
} catch (e) {
  if (e instanceof Error && e.message === 'Pusher client not initialized') {
    await PusherUtils.getPusherClient(baseURL, apiKey);
    PusherUtils.triggerSubscribe(clientId, fn);
  }
}

Prevention

When it happens

Trigger: Calling PusherUtils.triggerSubscribe(clientId, fn) (directly, or via a trigger API path that skips initialization) before awaiting getPusherClient(baseURL, apiKey) in the same process.

Common situations: Race where getPusherClient's promise isn't awaited; using the SDK in a fresh worker/process where only the subscribe path was invoked; code that caches a clientId across restarts and re-subscribes without re-initializing.

Related errors


AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28). Data as JSON: /api/errors/df30dc5793057231. Report an issue: GitHub.