{"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/677329427f32468c74b17f3ec47eeca4e05bec65/packages/server-sdk/src/client.ts#L338-L374","documentation":"server-sdk's AiriClient.send() builds the payload and delegates to transport.send, returning false when the transport cannot deliver (e.g. socket not open) (client.ts:343-352). sendOrThrow() wraps that boolean and throws this error, interpolating the client's current status so you can tell whether the socket is still connecting, disconnecting, or closed. It means the event was never handed to the network.","triggerScenarios":"Calling sendOrThrow before awaiting connect()/ready()/ensureConnected(), sending right after the socket dropped and before auto-reconnect finishes, or sending after close(). The status string in the message tells you which state the transport was in.","commonSituations":"Fire-and-forget usage that skips the connection promise, app shutdown paths that flush events after close, network blips where autoReconnect is disabled or still in its retry window.","solutions":["Await client.connect() (or ensureConnected/ready) before the first sendOrThrow","Use the boolean send() when a dropped event is acceptable, and queue it for retry on false","Enable autoReconnect and await the connection again after an onConnectionStateChange to disconnected"],"exampleFix":"// before\nconst client = createClient(opts)\nclient.sendOrThrow(event) // throws: status 'connecting'\n// after\nconst client = createClient(opts)\nawait client.ensureConnected()\nclient.sendOrThrow(event)","handlingStrategy":"validation","validationCode":"await client.ensureConnected() // resolves only when the transport is open\nif (!client.send(event)) {\n  // transport refused the frame; queue and retry after reconnect instead of throwing\n  pendingEvents.push(event)\n}","typeGuard":null,"tryCatchPattern":"try {\n  client.sendOrThrow(event)\n}\ncatch (error) {\n  if (error instanceof Error && error.message.startsWith('Client is not connected')) {\n    await client.ensureConnected()\n    client.sendOrThrow(event) // retry once after the socket is open\n  }\n  else throw error\n}","preventionTips":["Await connect()/ensureConnected() once at startup before any sendOrThrow","Prefer boolean send() plus an outbound queue for non-critical events","Subscribe to onConnectionStateChange and pause sends while disconnected"],"tags":["websocket","server-sdk","connection","send"],"backgroundTag":"websocket-not-connected","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}