{"record":{"id":"9bf65606e9124363","repo":"tursodatabase/turso","slug":"statement-execution-failed-with-status-result-s","errorCode":null,"errorMessage":"Statement execution failed with status: ${result.status}","messagePattern":"Statement execution failed with status: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"bindings/react-native/src/Statement.ts","lineNumber":199,"sourceCode":"   */\n  private async executeWithIo(): Promise<{ status: number; rowsChanged: number }> {\n    while (true) {\n      const result = this._statement.execute();\n\n      if (result.status === TursoStatus.IO) {\n        // Statement needs IO (e.g., loading missing pages with partial sync)\n        this._statement.runIo();\n\n        // Drain sync engine IO queue\n        if (this._extraIo) {\n          await this._extraIo();\n        }\n\n        continue;\n      }\n\n      if (result.status !== TursoStatus.DONE) {\n        throw new Error(`Statement execution failed with status: ${result.status}`);\n      }\n\n      return result;\n    }\n  }\n\n  /**\n   * Step statement once handling potential IO (for partial sync)\n   * Matches Python's _step_once_with_io pattern\n   *\n   * @returns Status code\n   */\n  private async stepWithIo(): Promise<number> {\n    while (true) {\n      const status = this._statement.step();\n\n      if (status === TursoStatus.IO) {\n        // Statement needs IO (e.g., loading missing pages with partial sync)","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/react-native/src/Statement.ts#L181-L217","documentation":"executeWithIo() loops calling runStep: a status of TursoStatus.IO means the statement needs IO (partial-sync page fetch), which the loop services via runIo() + draining the sync engine; DONE means success. Any other non-IO, non-DONE status reaching the check is a native execution failure, surfaced with its numeric status code.","triggerScenarios":"A run() whose native execution returns an unexpected status (e.g. an error/busy/invalid state code from the C engine) after IO retries; statements executed against a connection invalidated by an error earlier; internal errors in the native layer while running INSERT/UPDATE/DELETE.","commonSituations":"Rare in practice — this wraps native status codes that escape normal handling. When it appears, capture result.status and the SQL: it usually accompanies a native-level failure (corrupt state, unsupported operation, or a binding/native version mismatch after a partial upgrade).","solutions":["Log result.status together with the SQL and parameters; the numeric code identifies the native failure","Rebuild the app so the JS layer and the C++/native library are from the same package version (mismatched upgrades are a common source)","Reduce to a minimal reproduction (same SQL via db.exec) and report it with the status code to the Turso repo","Retry once on a fresh connection after closing and reopening the database to rule out transient connection state"],"exampleFix":"// before\nconst result = await stmt.run(params); // may throw opaque status error\n\n// after: capture status context for diagnosis\ntry {\n  const result = await stmt.run(params);\n} catch (e) {\n  reportError(e, { sql: stmtSql, params }); // message contains the status code\n  throw e;\n}","handlingStrategy":"retry","validationCode":"// No pre-check exists for native status codes; validate cheap health first\nawait db.get('SELECT 1'); // probe connection before critical writes\nconst result = await stmt.run(params);","typeGuard":null,"tryCatchPattern":"try {\n  await stmt.run(params);\n} catch (e) {\n  if (e instanceof Error && /failed with status/.test(e.message)) {\n    // one recovery attempt on a fresh connection, then surface with context\n    await resetDatabaseConnection();\n    return db.prepare(sql).run(params);\n  }\n  throw e;\n}","preventionTips":["Keep JS package and native binary versions in lockstep and rebuild on every upgrade","Log SQL + status code whenever this fires — the numeric status is the diagnosis entry point","Probe with 'SELECT 1' before critical write batches to separate connection-wide from statement-specific failures"],"tags":["react-native","statement","native-error","execution-status"],"backgroundTag":"statement-status-error","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}