{"record":{"id":"421d312548476f65","repo":"tursodatabase/turso","slug":"operation-returned-unexpected-result-type-resu","errorCode":null,"errorMessage":"{operation} returned unexpected result type: {result.Type}","messagePattern":"(.+?) returned unexpected result type: (.+?)","errorType":"exception","errorClass":"TursoException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoRemoteClient.cs","lineNumber":293,"sourceCode":"    {\n        if (response.Results.Count == 1)\n            return;\n        if (response.Results.Count > 2)\n            throw new TursoException($\"{operation} returned too many results.\");\n\n        var result = response.Results[1];\n        switch (result.Type)\n        {\n            case \"ok\":\n                if (result.Response?.Type != \"close\")\n                    throw new TursoException($\"{operation} returned unexpected response type: {result.Response?.Type}\");\n                break;\n\n            case \"error\":\n                break;\n\n            default:\n                throw new TursoException($\"{operation} returned unexpected result type: {result.Type}\");\n        }\n    }\n\n    private static List<RemoteStatementResult> ExtractBatchStepResults(RemoteBatchResult batch, int expectedCount)\n    {\n        if (batch.StepErrors.Count != expectedCount || batch.StepResults.Count != expectedCount)\n        {\n            throw new TursoException(\n                $\"Remote batch returned an unexpected result shape: {batch.StepResults.Count} results, {batch.StepErrors.Count} errors, expected {expectedCount}.\");\n        }\n\n        for (var i = 0; i < batch.StepErrors.Count; i++)\n        {\n            if (batch.StepErrors[i] is { } error)\n                throw CreateRemoteError(error);\n        }\n\n        var statementResults = new List<RemoteStatementResult>(expectedCount);","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data/TursoRemoteClient.cs#L275-L311","documentation":"When a statement or batch is sent with a trailing close request (closeAfter), the response should hold at most two entries: the statement/batch result and a close acknowledgment. ValidateOptionalTrailingClose threw because the trailing entry's type is neither \"ok\" nor \"error\" -- an unrecognized extra result where the close ack should be.","triggerScenarios":"Executing a command or batch on a remote connection in a mode that appends a close request (for example connection-close-after-execute paths): the response has exactly two entries and response.Results[1].Type falls outside ok/error. The operation string in the message tells you whether it came from 'Remote request' or 'Remote batch'.","commonSituations":"Server version drift that queues or reorders pipeline results; a server that injects extra entries (session/store results) the bindings do not expect; intermediaries appending entries to the results array.","solutions":["Capture the raw envelope and look at the second entry's type field to identify which layer produced it.","Upgrade server and Turso.Data bindings to matching versions.","Avoid middleware that appends or reorders entries in pipeline responses.","If you control the server, ensure close requests are answered with ok/close or error entries only.","Report the unexpected entry shape with the raw envelope attached."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await cmd.ExecuteNonQueryAsync(cancellationToken); }\ncatch (TursoException ex) when (ex.Message.Contains(\"returned unexpected result type\"))\n{\n    logger.LogError(ex, \"Trailing close ack malformed after {Sql}\", cmd.CommandText);\n    throw;\n}","preventionTips":["Upgrade bindings and server together so close-ack shapes stay compatible.","Do not append or reorder entries in pipeline responses at any middleware layer.","When self-hosting, answer close requests strictly with ok/close or error entries.","Capture the full envelope (including the trailing entry) when reporting."],"tags":["turso","dotnet","remote","protocol","connection-close"],"backgroundTag":"unexpected-response-type","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}