Skip to content

Commit

Permalink
Merge pull request #660 from JanKrivanek/proto/newer-v-info-in-error
Browse files Browse the repository at this point in the history
Add newer version info in file version error
  • Loading branch information
KirillOsenkov authored Feb 28, 2023
2 parents 54aa11f + 1b496eb commit 512f695
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/StructuredLogViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private async System.Threading.Tasks.Task UpdateApplicationAsync()
{
var versionText = result.Version.ToString();
message = "After restarting the app you will be on version " + versionText;
BinaryLogger.IsNewerVersionAvailable = true;
FileAssociations.EnsureAssociationsSet(versionText);
}
else
Expand Down
31 changes: 17 additions & 14 deletions src/StructuredLogger/BinaryLogger/BinLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ public void Replay(Stream stream, Progress progress)

OnFileFormatVersionRead?.Invoke(fileFormatVersion);

// the log file is written using a newer version of file format
// that we don't know how to read
if (fileFormatVersion > BinaryLogger.FileFormatVersion)
{
var text = $"Unsupported log file format. Latest supported version is {BinaryLogger.FileFormatVersion}, the log file has version {fileFormatVersion}.";
throw new NotSupportedException(text);
}
EnsureFileFormatVersionKnown(fileFormatVersion);

// Use a producer-consumer queue so that IO can happen on one thread
// while processing can happen on another thread decoupled. The speed
Expand Down Expand Up @@ -143,6 +137,21 @@ public void Replay(Stream stream, Progress progress)
}
}

private void EnsureFileFormatVersionKnown(int fileFormatVersion)
{
// the log file is written using a newer version of file format
// that we don't know how to read
if (fileFormatVersion > BinaryLogger.FileFormatVersion)
{
var text = $"Unsupported log file format. Latest supported version is {BinaryLogger.FileFormatVersion}, the log file has version {fileFormatVersion}.";
if (BinaryLogger.IsNewerVersionAvailable)
{
text += " Update available - restart this instance to automatically use newer version.";
}
throw new NotSupportedException(text);
}
}

private class DisposableEnumerable<T> : IEnumerable<T>, IDisposable
{
private IEnumerable<T> enumerable;
Expand Down Expand Up @@ -210,13 +219,7 @@ public IEnumerable<Record> ReadRecordsFromDecompressedStream(Stream decompressed

int fileFormatVersion = binaryReader.ReadInt32();

// the log file is written using a newer version of file format
// that we don't know how to read
if (fileFormatVersion > BinaryLogger.FileFormatVersion)
{
var text = $"Unsupported log file format. Latest supported version is {BinaryLogger.FileFormatVersion}, the log file has version {fileFormatVersion}.";
throw new NotSupportedException(text);
}
EnsureFileFormatVersionKnown(fileFormatVersion);

long lengthOfBlobsAddedLastTime = 0;

Expand Down
2 changes: 2 additions & 0 deletions src/StructuredLogger/BinaryLogger/BinaryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public sealed class BinaryLogger : ILogger
// - AssemblyLoadBuildEventArgs
internal const int FileFormatVersion = 16;

public static bool IsNewerVersionAvailable { get; set; }

private Stream stream;
private BinaryWriter binaryWriter;
private BuildEventArgsWriter eventArgsWriter;
Expand Down

0 comments on commit 512f695

Please sign in to comment.