Fix file lock not getting disposed when postamble throws an exception

pull/1001/head
Tyrrrz 2 years ago
parent a68df7a065
commit bf76f10030

@ -33,6 +33,8 @@ public class ExportWrapperFixture : IDisposable
// Perform export only if it hasn't been done before
if (!File.Exists(filePath))
{
try
{
await new ExportChannelsCommand
{
@ -42,6 +44,13 @@ public class ExportWrapperFixture : IDisposable
OutputPath = filePath
}.ExecuteAsync(new FakeConsole());
}
catch
{
// If the export fails, delete the file to prevent it from being used by tests
File.Delete(filePath);
throw;
}
}
return await File.ReadAllTextAsync(filePath);
}

@ -22,12 +22,19 @@ internal partial class MessageExporter : IAsyncDisposable
private async ValueTask ResetWriterAsync(CancellationToken cancellationToken = default)
{
if (_writer is not null)
{
try
{
await _writer.WritePostambleAsync(cancellationToken);
}
// Writer must be disposed, even if writing postamble fails
finally
{
await _writer.DisposeAsync();
_writer = null;
}
}
}
private async ValueTask<MessageWriter> GetWriterAsync(CancellationToken cancellationToken = default)
{

@ -67,9 +67,7 @@ internal class HtmlMessageWriter : MessageWriter
}
// Use <!--wmm:ignore--> to preserve blocks of code inside the templates
private string Minify(string html) => _minifier
.Minify(html, false)
.MinifiedContent;
private string Minify(string html) => _minifier.Minify(html, false).MinifiedContent;
public override async ValueTask WritePreambleAsync(
CancellationToken cancellationToken = default)

Loading…
Cancel
Save