KirillOsenkov / MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
MIT License
1.41k stars 188 forks source link

Cannot open Czech log files #744

Closed manison closed 5 months ago

manison commented 5 months ago

Binary logs created on systems with Czech locale cannot be open in StructuredLogViewer. When opening the log there is an exception

System.ArgumentException
Analysis ^Opětovné přiřazení vlastnosti: $({0})={1} (předchozí hodnota: {2}) v (?<File>.*) \((?<Line>\d+),(?<Column>\d+)\)$ - Quantifier '{x,y}' following nothing.

in

https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/e55698cfee98afab9b2221aa9b24c97f86d92ce7/src/StructuredLogger/Strings/Strings.cs#L144-L150

    System.dll!System.Text.RegularExpressions.RegexParser.ScanRegex()   Unknown
    System.dll!System.Text.RegularExpressions.RegexParser.Parse(string re, System.Text.RegularExpressions.RegexOptions op)  Unknown
    System.dll!System.Text.RegularExpressions.Regex.Regex(string pattern, System.Text.RegularExpressions.RegexOptions options, System.TimeSpan matchTimeout, bool useCache) Unknown
    System.dll!System.Text.RegularExpressions.Regex.Regex(string pattern, System.Text.RegularExpressions.RegexOptions options)  Unknown
>   StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.Strings.InitializeRegex() Line 150    C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.Strings.Initialize(string culture) Line 22    C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.OnMessageRead(Microsoft.Build.Framework.BuildMessageEventArgs args) Line 119 C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.ReadBuildMessageEventArgs() Line 1086    C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.ReadBuildEventArgs(Microsoft.Build.Logging.StructuredLogger.BinaryLogRecordKind recordKind) Line 309 C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.Read() Line 236  C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.BinLogReader.Replay(System.IO.Stream stream, Microsoft.Build.Logging.StructuredLogger.Progress progress) Line 91  C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(System.IO.Stream stream, Microsoft.Build.Logging.StructuredLogger.Progress progress, byte[] projectImportsArchive, Microsoft.Build.Logging.StructuredLogger.ReaderSettings readerSettings) Line 130   C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(string filePath, Microsoft.Build.Logging.StructuredLogger.Progress progress, Microsoft.Build.Logging.StructuredLogger.ReaderSettings readerSettings) Line 44  C#
    StructuredLogger.dll!Microsoft.Build.Logging.StructuredLogger.Serialization.Read(string filePath, Microsoft.Build.Logging.StructuredLogger.Progress progress, Microsoft.Build.Logging.StructuredLogger.ReaderSettings readerSettings) Line 62   C#
    StructuredLogViewer.exe!StructuredLogViewer.MainWindow.OpenLogFile.AnonymousMethod__5() Line 497    C#
    mscorlib.dll!System.Threading.Tasks.Task<Microsoft.Build.Logging.StructuredLogger.Build>.InnerInvoke()  Unknown
    mscorlib.dll!System.Threading.Tasks.Task.Execute()  Unknown
    mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
    mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot)    Unknown
    mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) Unknown
    mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()    Unknown

This is because the Czech string

Opětovné přiřazení vlastnosti: $({0})={1} (předchozí hodnota: {2}) v {3}

apparently does not make a valid regular expression.

There are quotes around the "quantifier" in other languages, in English:

Property reassignment: $({0})=\"{1}\" (previous value: \"{2}\") at {3}
KirillOsenkov commented 5 months ago

Indeed, it is also broken for: "cs-CZ", "ko-KR", "pl-PL" and "zh-Hans"

KirillOsenkov commented 5 months ago

I made a fix, if it's not hard, would be nice if you could clone the repo, pull latest main branch, msbuild /r /m /bl MSBuildStructuredLog.sln and see if the locally built version works fine for your binlog.

If it looks good, I can publish an update.

KirillOsenkov commented 5 months ago

I published https://github.com/KirillOsenkov/MSBuildStructuredLog/releases/tag/v2.2.163

manison commented 5 months ago

It works great, thanks!