{"record":{"id":"2f4a8110337adbbb","repo":"mem0ai/mem0","slug":"baidu-mochow-action-failed-code-response-cod","errorCode":null,"errorMessage":"Baidu Mochow ${action} failed (code ${response.code}): ${response.msg}","messagePattern":"Baidu Mochow (.+?) failed \\(code (.+?)\\): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/baidu.ts","lineNumber":69,"sourceCode":"\nfunction escapeFilterString(value: string): string {\n  return value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\nfunction sleep(ms: number): Promise<void> {\n  return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// Mochow resolves with a {code, msg} envelope instead of rejecting, so every call site\n// has to inspect the code. `tolerated` lets callers accept the idempotent outcomes\n// (database/table already exists, table already dropped).\nfunction check(\n  response: CommonResponse,\n  action: string,\n  ...tolerated: number[]\n): number {\n  if (response.code !== 0 && !tolerated.includes(response.code)) {\n    throw new Error(\n      `Baidu Mochow ${action} failed (code ${response.code}): ${response.msg}`,\n    );\n  }\n  return response.code;\n}\n\nfunction lemmatizedText(payload: Record<string, any>): string {\n  const data = typeof payload.data === \"string\" ? payload.data : \"\";\n  return typeof payload.textLemmatized === \"string\" &&\n    payload.textLemmatized.length > 0\n    ? payload.textLemmatized\n    : data;\n}\n\nfunction memoryData(payload: Record<string, any>): string {\n  return typeof payload.data === \"string\" ? payload.data : \"\";\n}\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/baidu.ts#L51-L87","documentation":"The Baidu Mochow SDK resolves calls with a {code, msg} envelope instead of rejecting, so mem0 wraps every operation in check(), which throws this error when code !== 0 and the code is not in the caller's tolerated list (idempotent outcomes like 'database already exists' are tolerated). The message includes the action name (e.g. createDatabase, dropTable), the numeric code, and Mochow's msg.","triggerScenarios":"createTable failing because the account has no permission on the database; a network/SDK error code returned by Mochow; dropping a table that is in a transitioning state; any Mochow RPC whose code is non-zero and not idempotent-tolerated.","commonSituations":"Wrong Baidu account/apiKey; quota or region limits; running two Memory instances concurrently so createDatabase races past tolerated codes; SDK version returning new error codes.","solutions":["Decode the code/msg pair against Baidu Mochow docs: permission issues mean fix account/API key; 'already exists' variants are usually tolerated automatically, other codes are real failures.","Verify endpoint/account/apiKey in the vector store config are for the same Baidu project and region.","Retry initialization after transient codes; if racing instances created the database concurrently, restart one after the other is settled."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await memory.add(text) }\ncatch (e) {\n  if (e instanceof Error && /Baidu Mochow .* failed \\(code \\d+\\)/.test(e.message)) {\n    const code = Number(/code (\\d+)/.exec(e.message)?.[1]);\n    if (isTransientMochowCode(code)) await backoffRetry(() => memory.add(text), 3);\n    else throw new Error(`Baidu setup/permission failure: ${e.message}`);\n  } else throw e;\n}","preventionTips":["Verify endpoint/account/apiKey against the Baidu console before first run.","Run a single Memory instance for first-time database/table creation to avoid races.","Map known transient Mochow codes to retries in a wrapper instead of crashing."],"tags":["baidu","mochow","vector-store","rpc","error-envelope"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}