Skip to content

Commit

Permalink
Add error handling when opening corrupt log files. Fixes #41.
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillOsenkov committed Nov 5, 2016
1 parent 9e8a0e5 commit b83404f
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/StructuredLogViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void DisplayWelcomeScreen(string message = "")
this.logFilePath = null;
this.currentBuild = null;
Title = DefaultTitle;

var welcomeScreen = new WelcomeScreen();
welcomeScreen.Message = message;
SetContent(welcomeScreen);
Expand Down Expand Up @@ -217,12 +218,31 @@ private async void OpenLogFile(string filePath)
var progress = new BuildProgress();
progress.ProgressText = "Opening " + filePath + "...";
SetContent(progress);

bool shouldAnalyze = true;

Build build = await System.Threading.Tasks.Task.Run(() =>
{
return Serialization.Read(filePath);
try
{
return Serialization.Read(filePath);
}
catch (Exception ex)
{
shouldAnalyze = false;
build = new Build() { Succeeded = false };
build.AddChild(new Error() { Text = "Error when opening file: " + filePath });
build.AddChild(new Error() { Text = ex.ToString() });
return build;
}
});
progress.ProgressText = "Analyzing " + filePath + "...";
await System.Threading.Tasks.Task.Run(() => BuildAnalyzer.AnalyzeBuild(build));

if (shouldAnalyze)
{
progress.ProgressText = "Analyzing " + filePath + "...";
await System.Threading.Tasks.Task.Run(() => BuildAnalyzer.AnalyzeBuild(build));
}

DisplayBuild(build);
}

Expand Down

0 comments on commit b83404f

Please sign in to comment.