Skip to content

Commit

Permalink
Suppressed a COMException which can happen when debugging
Browse files Browse the repository at this point in the history
This would be caused because Visual Studio is currently on a break point and the log can't be produced.
  • Loading branch information
ByronMayne committed Jan 21, 2024
1 parent 7e580cf commit f6097d9
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EnvDTE;
using SGF.Diagnostics;
using System;
using System.Runtime.InteropServices;
using Constants = EnvDTE.Constants;

namespace SGF.Interop.VisualStudio
Expand Down Expand Up @@ -96,10 +97,10 @@ public void Write(LogLevel logLevel, string message)

if (logLevel >= LogLevel.Warning)
{
m_buildOutput?.OutputString(message);
Write(message);
}

m_sourceGeneratorOutput?.OutputString(message);
Write(message);
}


Expand All @@ -108,17 +109,24 @@ public void Write(LogLevel logLevel, string message)
/// </summary>
public void Write(string message)
{
m_sourceGeneratorOutput?.OutputString(message);
try
{
m_sourceGeneratorOutput?.OutputString(message);
}
catch (COMException)
{
// When the person is debugging Visual Studio will be busy and this will throw this exception
}
catch(Exception exception)
{
Console.WriteLine($"Exception was thrown while writing log. Please report this on gihub {exception}");
}
}



/// <summary>
/// Writes an entry to the output window if it has been initialized
/// </summary>
public void WriteLine(string message)
{
m_sourceGeneratorOutput?.OutputString($"{message}{Environment.NewLine}");
}
=> Write($"{message}{Environment.NewLine}");
}
}

0 comments on commit f6097d9

Please sign in to comment.