Skip to content

Commit 24e6326

Browse files
author
BRUNER Patrick
committed
review comments
1 parent 01b8511 commit 24e6326

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

src/LogExpert.Tests/Services/ProjectFileHandlerTests.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public void TearDown ()
7575
public void LoadProject_ValidProjectFile_ReturnsSuccess ()
7676
{
7777
// Arrange: create a real log file so validation passes
78-
var logFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".log");
79-
File.WriteAllText(logFile, "test log line");
78+
var logFile = CreateTempLogFile();
8079
var tempFile = CreateTempProjectFile([logFile], layoutXml: null);
8180

8281
try
@@ -93,17 +92,16 @@ public void LoadProject_ValidProjectFile_ReturnsSuccess ()
9392
}
9493
finally
9594
{
96-
File.Delete(tempFile);
9795
File.Delete(logFile);
96+
File.Delete(tempFile);
9897
}
9998
}
10099

101100
[Test]
102101
public void LoadProject_ValidProjectWithLayoutXml_HasLayoutDataIsTrue ()
103102
{
104103
// Arrange: create a real log file so validation passes
105-
var logFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".log");
106-
File.WriteAllText(logFile, "test log line");
104+
var logFile = CreateTempLogFile();
107105
var tempFile = CreateTempProjectFile([logFile], layoutXml: "<DockPanel><Content/></DockPanel>");
108106

109107
try
@@ -610,6 +608,16 @@ private static ProjectLoadOutcome CreateOutcome (ProjectLoadOutcome.LoadStatus s
610608
};
611609
}
612610

611+
private static string CreateTempLogFile ()
612+
{
613+
var tempPathFile = Path.GetTempFileName();
614+
var logFile = Path.ChangeExtension(tempPathFile, ".log")!;
615+
File.WriteAllText(logFile, "test log line");
616+
File.Delete(tempPathFile);
617+
618+
return logFile;
619+
}
620+
613621
/// <summary>
614622
/// Creates a temporary .lxj project file with the given file names and optional layout XML. Returns the path to the
615623
/// temp file.

src/LogExpert.UI/Services/ProjectFileHandlerService/ProjectFileHandler.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ public ProjectLoadOutcome LoadProject (string projectFileName)
7676
LayoutXml = layoutXml
7777
};
7878
}
79-
catch (Exception ex)
79+
catch (Exception ex) when (ex is IOException or
80+
UnauthorizedAccessException or
81+
InvalidOperationException or
82+
Newtonsoft.Json.JsonException)
8083
{
8184
_logger.Error(ex, "LoadProject: Exception loading {FileName}", projectFileName);
8285

@@ -116,7 +119,10 @@ public ContinueLoadResult ContinueLoad (ProjectLoadOutcome loadOutcome, MissingF
116119
ProjectPersister.SaveProjectData(projectData.ProjectFilePath, projectData);
117120
_logger.Info("ContinueLoad: Updated session file {FileName}", projectData.ProjectFilePath);
118121
}
119-
catch (Exception ex)
122+
catch (Exception ex) when (ex is IOException or
123+
UnauthorizedAccessException or
124+
InvalidOperationException or
125+
ArgumentException)
120126
{
121127
_logger.Error(ex, "ContinueLoad: Failed to update session file {FileName}", projectData.ProjectFilePath);
122128
}
@@ -154,7 +160,14 @@ public ContinueLoadResult ContinueLoad (ProjectLoadOutcome loadOutcome, MissingF
154160
_ = addFileTab(request);
155161
openedCount++;
156162
}
157-
catch (Exception ex)
163+
catch (Exception ex) when (ex is not OutOfMemoryException
164+
and not StackOverflowException
165+
and not AccessViolationException
166+
and not AppDomainUnloadedException
167+
and not BadImageFormatException
168+
and not CannotUnloadAppDomainException
169+
and not InvalidProgramException
170+
and not ThreadAbortException)
158171
{
159172
_logger.Error(ex, "ContinueLoad: Failed to open tab for {FileName}", fileName);
160173
}
@@ -176,7 +189,10 @@ public bool SaveProject (string projectFileName, ProjectData projectData, out st
176189
errorMessage = null;
177190
return true;
178191
}
179-
catch (Exception ex)
192+
catch (Exception ex) when (ex is IOException or
193+
UnauthorizedAccessException or
194+
InvalidOperationException or
195+
ArgumentException)
180196
{
181197
_logger.Error(ex, "SaveProject: Failed to save {FileName}", projectFileName);
182198
errorMessage = $"Error saving project: {ex.Message}";

0 commit comments

Comments
 (0)