Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace2FileWriter: ignore some exceptions on write #1340

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/shared/Core/Trace2FileWriter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;

namespace GitCredentialManager;

Expand All @@ -13,6 +14,22 @@ public Trace2FileWriter(Trace2FormatTarget formatTarget, string path) : base(for

public override void Write(Trace2Message message)
{
File.AppendAllText(_path, Format(message));
try
{
File.AppendAllText(_path, Format(message));
}
catch (DirectoryNotFoundException)
{
// Do nothing, as this either means we don't have the
// parent directories above the file, or this trace2
// target points to a directory.
}
catch (UnauthorizedAccessException)
{
// Do nothing, as this either means the file is not
// accessible with current permissions, or we are on
// Windows and the file is currently open for writing
// by another process (likely Git itself.)
}
}
}