{"record":{"id":"5ecfc3dca967a4cb","repo":"mem0ai/mem0","slug":"failed-to-set-user-id-error-instanceof-error","errorCode":null,"errorMessage":"Failed to set user ID: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to set user ID: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/vectorize.ts","lineNumber":365,"sourceCode":"      const data: VectorizeVector = {\n        id: pointId,\n        values: [0],\n        metadata: { userId },\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    } catch (error) {\n      console.error(\"Error setting user ID:\", error);\n      throw new Error(\n        `Failed to set user ID: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }\n\n  async initialize(): Promise<void> {\n    if (!this._initPromise) {\n      this._initPromise = this._doInitialize();\n    }\n    return this._initPromise;\n  }\n\n  private async _doInitialize(): Promise<void> {\n    await this.ensureClient();\n    try {\n      // Check if the index already exists\n      let indexFound = false;\n      for await (const idx of this.client!.vectorize.indexes.list({","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/vectorize.ts#L347-L383","documentation":"Error \"Failed to set 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:365 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the Cloudflare API token has write permissions for Vectorize.","Check that the metadata payload is within Vectorize size limits.","Retry transient network failures with backoff."],"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-15T17:31:12.345Z"}