Path: redb-route/redb.Route.Sql/Batch/BatchRollback.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Sql/Batch/BatchRollback.cs
----
using System.Data.Common;
using Microsoft.Extensions.Logging;
namespace redb.Route.Sql.Batch;
/// Rolls a failed batch back without letting a failing rollback replace the error that caused it.
internal static class BatchRollback
{
///
/// Rolls back with — a cancelled batch still has to release its transaction. A rollback
/// that fails (typically: the server already ended the transaction) is logged; the caller's original exception is what
/// propagates.
///
internal static async Task RunAsync(DbTransaction transaction, ILogger? logger)
{
try
{
await transaction.RollbackAsync(CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
logger?.LogError(ex, "SQL batch transaction rollback failed; the error that ended the batch is rethrown");
}
}
}