diff --git a/src/EntglDb.Persistence.Sqlite/SqlitePeerStore.cs b/src/EntglDb.Persistence.Sqlite/SqlitePeerStore.cs index e3c9a64..4155a47 100644 --- a/src/EntglDb.Persistence.Sqlite/SqlitePeerStore.cs +++ b/src/EntglDb.Persistence.Sqlite/SqlitePeerStore.cs @@ -870,13 +870,27 @@ INSERT INTO Oplog (Collection, Key, Operation, JsonData, HlcWall, HlcLogic, HlcN catch (SqliteException ex) when (ex.SqliteErrorCode == 11 || ex.SqliteErrorCode == 26) // SQLITE_CORRUPT or SQLITE_NOTADB { _logger.LogCritical(ex, "Database corruption detected during ApplyBatchAsync!"); - try { transaction.Rollback(); } catch { } + try + { + transaction.Rollback(); + } + catch (Exception rollbackEx) + { + _logger.LogWarning(rollbackEx, "Failed to rollback transaction after database corruption"); + } throw new CorruptDatabaseException("SQLite database is corrupt", ex); } catch (Exception ex) { _logger.LogError(ex, "Failed to apply batch"); - try { transaction.Rollback(); } catch { } + try + { + transaction.Rollback(); + } + catch (Exception rollbackEx) + { + _logger.LogWarning(rollbackEx, "Failed to rollback transaction after batch failure"); + } throw; } @@ -1023,12 +1037,27 @@ DELETE FROM Oplog catch (SqliteException ex) when (ex.SqliteErrorCode == 11 || ex.SqliteErrorCode == 26) // SQLITE_CORRUPT or SQLITE_NOTADB { _logger.LogCritical(ex, "Database corruption detected during oplog pruning (PruneOplogAsync)."); - try { transaction.Rollback(); } catch { } + try + { + transaction.Rollback(); + } + catch (Exception rollbackEx) + { + _logger.LogWarning(rollbackEx, "Failed to rollback transaction after database corruption during oplog pruning"); + } throw new CorruptDatabaseException("SQLite database is corrupt", ex); } catch (Exception ex) { _logger.LogError(ex, "Failed to prune oplog"); + try + { + transaction.Rollback(); + } + catch (Exception rollbackEx) + { + _logger.LogWarning(rollbackEx, "Failed to rollback transaction after oplog pruning failure"); + } throw; } }