tursodatabase/turso · error · TursoException

Remote batch returned an unexpected result shape: {batch.Ste

Error message

Remote batch returned an unexpected result shape: {batch.StepResults.Count} results, {batch.StepErrors.Count} errors, expected {expectedCount}.

What it means

For a batch, the server must return exactly one step_results entry and one step_errors entry per submitted command. ExtractBatchStepResults threw because those arrays' lengths differ from the number of TursoBatchCommands sent, meaning the reply does not line up with the request.

Source

Thrown at bindings/dotnet/src/Turso.Data/TursoRemoteClient.cs:301

        {
            case "ok":
                if (result.Response?.Type != "close")
                    throw new TursoException($"{operation} returned unexpected response type: {result.Response?.Type}");
                break;

            case "error":
                break;

            default:
                throw new TursoException($"{operation} returned unexpected result type: {result.Type}");
        }
    }

    private static List<RemoteStatementResult> ExtractBatchStepResults(RemoteBatchResult batch, int expectedCount)
    {
        if (batch.StepErrors.Count != expectedCount || batch.StepResults.Count != expectedCount)
        {
            throw new TursoException(
                $"Remote batch returned an unexpected result shape: {batch.StepResults.Count} results, {batch.StepErrors.Count} errors, expected {expectedCount}.");
        }

        for (var i = 0; i < batch.StepErrors.Count; i++)
        {
            if (batch.StepErrors[i] is { } error)
                throw CreateRemoteError(error);
        }

        var statementResults = new List<RemoteStatementResult>(expectedCount);
        for (var i = 0; i < batch.StepResults.Count; i++)
        {
            var stepResult = batch.StepResults[i]
                             ?? throw new TursoException($"Remote batch did not return a result for step {i}.");
            statementResults.Add(stepResult);
        }

        return statementResults;

View on GitHub (pinned to 244cde92a7)

Solutions

  1. Log the batch size you submitted and the counts in the message (the exception text includes results, errors, and expected counts) to see which side is off.
  2. Reproduce the batch pipeline POST with curl and count the step arrays in the raw JSON.
  3. Align server and Turso.Data binding versions; batch shape changes are common across protocol revisions.
  4. Remove truncating or transforming proxies from the path.
  5. If the server intentionally changed shape, upgrade the bindings to the release that understands it.
Defensive patterns

Strategy: try-catch

Try / catch

try { return await batch.ExecuteReaderAsync(cancellationToken); }
catch (TursoException ex) when (ex.Message.Contains("unexpected result shape"))
{
    // message contains actual vs expected counts: log it verbatim
    logger.LogError(ex, "Batch step count mismatch for batch of {Count}", batch.BatchCommands.Count);
    throw;
}

Prevention

When it happens

Trigger: TursoBatch execution on a remote connection where batch.step_results.Count or batch.step_errors.Count differs from commands.Count -- for example 3 commands submitted but 2 step results returned.

Common situations: Servers that deduplicate or collapse identical statements in a batch; response truncation by a proxy; version drift changing batch result semantics; custom servers returning a single aggregate result instead of per-step results.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/b451e9103301b9bd. Report an issue: GitHub.