{"record":{"id":"e4baa14220305516","repo":"mem0ai/mem0","slug":"failed-to-get-user-id-error-instanceof-error","errorCode":null,"errorMessage":"Failed to get user ID: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to get user ID: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/vectorize.ts","lineNumber":325,"sourceCode":"        values: [0],\n        metadata: { userId: randomUserId },\n      };\n\n      await fetch(\n        `https://api.cloudflare.com/client/v4/accounts/${this.accountId}/vectorize/v2/indexes/memory_migrations/upsert`,\n        {\n          method: \"POST\",\n          headers: {\n            \"Content-Type\": \"application/x-ndjson\",\n            Authorization: `Bearer ${this.client?.apiToken}`,\n          },\n          body: JSON.stringify(data) + \"\\n\", // ndjson format\n        },\n      );\n      return randomUserId;\n    } catch (error) {\n      console.error(\"Error getting user ID:\", error);\n      throw new Error(\n        `Failed to get user ID: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }\n\n  async setUserId(userId: string): Promise<void> {\n    await this.initialize();\n    try {\n      // Get existing point ID\n      const result: any = await this.client?.vectorize.indexes.query(\n        \"memory_migrations\",\n        {\n          account_id: this.accountId,\n          vector: [0],\n          topK: 1,\n          returnMetadata: \"all\",\n        },\n      );","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/vectorize.ts#L307-L343","documentation":"Error \"Failed to get user ID: ${error instanceof Error ? error.message : String(error)}\" thrown in mem0ai/mem0.","triggerScenarios":"Thrown at mem0-ts/src/oss/src/vector_stores/vectorize.ts:325 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the Cloudflare API token has account-level read permissions.","Check network connectivity to the Cloudflare API.","Retry with exponential backoff for transient failures."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}