{"record":{"id":"0f00eda7758a7d67","repo":"cube-js/cube","slug":"invalid-message-format","errorCode":null,"errorMessage":"Invalid message format","messagePattern":"Invalid message format","errorType":"validation","errorClass":"CubejsHandlerError","httpStatus":400,"severity":"error","filePath":"packages/cubejs-api-gateway/src/ws/subscription-server.ts","lineNumber":86,"sourceCode":"      if (!result.success) {\n        throw new CubejsHandlerError(400, 'Invalid authorization message format', this.mapZodError(result.error));\n      }\n\n      return result.data;\n    }\n\n    if ('unsubscribe' in message) {\n      const result = unsubscribeMessageSchema.safeParse(message);\n      if (!result.success) {\n        throw new CubejsHandlerError(400, 'Invalid unsubscribe message format', this.mapZodError(result.error));\n      }\n\n      return result.data;\n    }\n\n    const result = methodMessageSchema.safeParse(message);\n    if (!result.success) {\n      throw new CubejsHandlerError(400, 'Invalid message format', this.mapZodError(result.error));\n    }\n\n    return result.data;\n  }\n\n  public async processMessage(connectionId: string, body: string) {\n    let message: any | undefined;\n\n    try {\n      message = this.deserializeMessage(body);\n      message = this.validateMessage(message);\n\n      await this.handleMessage(connectionId, message, false);\n    } catch (e) {\n      this.apiGateway.handleError({\n        e,\n        query: message?.query,\n        res: this.resultFn(connectionId, message?.messageId, undefined, false),","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-api-gateway/src/ws/subscription-server.ts#L68-L104","documentation":"Any WebSocket message that is neither an authorization nor an unsubscribe message falls through to methodMessageSchema, which requires a valid 'method' field (one of the supported methods) plus method-specific payload. Zod failure throws CubejsHandlerError(400, 'Invalid message format') with a detail naming the missing/invalid field.","triggerScenarios":"Sending { ... } without a recognized method, misspelling it (e.g. 'Load' vs 'load'), omitting required fields like messageId or query, or including only unknown properties.","commonSituations":"Custom WS integrations guessing the protocol; sending REST-style payloads over WS; sending ping/heartbeat frames as regular messages; old client library talking to a newer server schema (or vice versa).","solutions":["Send { messageId: '<id>', method: 'load'|'subscribe'|..., <methodPayload> } exactly as the schema requires; check methodMessageSchema for the version in use.","Read the Zod detail after the error message to identify the exact missing/invalid field.","Use @cubejs-client/core with the WebSocket transport instead of raw protocol messages."],"exampleFix":"// before\nsocket.send(JSON.stringify({ method: 'fetch', query: {} }));\n// after\nsocket.send(JSON.stringify({ messageId: '1', method: 'load', query: { measures: ['Orders.count'] } }));","handlingStrategy":"validation","validationCode":"function isValidMethodMessage(msg: unknown): boolean {\n  const m = msg as any;\n  const METHODS = ['load', 'subscribe'];\n  return typeof m === 'object' && m !== null &&\n    typeof m.messageId === 'string' &&\n    METHODS.includes(m.method);\n}","typeGuard":"function isMethodMessage(m: unknown): m is { messageId: string, method: 'load' | 'subscribe', [k: string]: unknown } {\n  return typeof m === 'object' && m !== null && typeof (m as any).method === 'string';\n}","tryCatchPattern":"try {\n  await handleMessage(frame);\n} catch (e) {\n  if (e.status === 400 && e.error === 'Invalid message format') {\n    console.error('Method frame rejected:', e.message); // Zod path/message details\n  } else throw e;\n}","preventionTips":["Use @cubejs-client/core with WebSocketTransport instead of hand-rolled WS protocol calls.","Always include messageId and a valid method name per methodMessageSchema.","Validate the outgoing object against the schema locally in tests.","Keep client and server versions in sync to avoid protocol drift."],"tags":["websocket","validation","zod","protocol"],"backgroundTag":"invalid-message-format","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}