{"record":{"id":"87b8062c1fa4ddd5","repo":"moeru-ai/airi","slug":"client-is-not-connected-current-status-this-st","errorCode":null,"errorMessage":"Client is not connected, current status: ${this.status}","messagePattern":"Client is not connected, current status: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server-sdk/src/client.ts","lineNumber":356,"sourceCode":"    }\n\n    this.eventListeners.delete(event)\n  }\n\n  send(data: WebSocketEventOptionalSource<C>): boolean {\n    const payload = this.createPayload(data)\n    const result = this.transport.send(payload)\n    if (!result.ok) {\n      return false\n    }\n\n    this.opts.onAnySend(payload)\n    return true\n  }\n\n  sendOrThrow(data: WebSocketEventOptionalSource<C>): void {\n    if (!this.send(data)) {\n      throw new Error(`Client is not connected, current status: ${this.status}`)\n    }\n  }\n\n  close(code?: number, reason?: string): void {\n    this.transport.close(code, reason)\n  }\n\n  private createReconnectOptions(): false | ReconnectOptions {\n    if (!this.opts.autoReconnect) {\n      return false\n    }\n\n    return {\n      retries: (attempt, error) => {\n        const normalized = this.normalizeError(error, 'Failed to connect websocket client')\n        if (isTerminalAuthenticationServerErrorMessage(normalized.message)) {\n          return false\n        }","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/packages/server-sdk/src/client.ts#L338-L374","documentation":"Thrown by `Client.sendOrThrow()` when the underlying `send()` returns false, meaning the transport reported a non-OK send result (typically because the socket is not open/connected). The message includes the current connection `status` to aid diagnosis. `sendOrThrow` is the throwing variant of `send()`, which otherwise returns a boolean.","triggerScenarios":"Calling `client.sendOrThrow(event)` while the client is not in a connected state — e.g. before the connection has opened, after it has closed, during reconnection backoff, or after a terminal auth failure. Any transport send that returns `{ ok: false }` triggers it.","commonSituations":"Sending immediately after constructing the client without waiting for the open/ready event; sending during/after an unexpected disconnect; sending after the server closed the connection (auth failure, idle timeout); calling sendOrThrow in an event handler that fires post-close.","solutions":["Wait for the client's connected/open status before sending, or prefer the non-throwing `send()` and check its boolean return.","Enable `autoReconnect` and queue outbound events until reconnection succeeds, rather than sending during a disconnected window.","Inspect the `status` field in the error message to identify the state (connecting/closed/reconnecting) and act accordingly.","Handle terminal auth failures distinctly so you do not keep retrying sends on a dead session."],"exampleFix":"// before\nclient.sendOrThrow(event)\n\n// after\nif (!client.send(event)) {\n  queue.push(event) // replay once reconnected\n}","handlingStrategy":"validation","validationCode":"if (!client.send(event)) {\n  // transport reported not-OK; queue and replay, or surface to the user\n  outboundQueue.push(event)\n}","typeGuard":"function isClientReady(client: { status: string }): boolean {\n  return client.status === 'open' || client.status === 'connected'\n}","tryCatchPattern":"try {\n  client.sendOrThrow(event)\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Client is not connected')) {\n    outboundQueue.push(event) // replay once reconnected\n    return\n  }\n  throw e\n}","preventionTips":["Prefer the boolean send() and handle false returns by queuing, rather than sendOrThrow, unless you want a hard failure.","Wait for the connected/open signal before sending.","Enable autoReconnect and replay queued events after reconnection.","Distinguish terminal auth failures so you stop sending on a dead session."],"tags":["server-sdk","websocket-client","transport","connection-state"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}