Skip to content

Commit

Permalink
Update NatashaExceptionAnalyzer.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
NMSAzulX committed Jul 1, 2024
1 parent 77dc858 commit ae62595
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ internal sealed class NatashaExceptionAnalyzer

var diagnostics = tree.GetDiagnostics();
var errors = diagnostics.Where(item => !item.IsSuppressed).ToArray();
if (errors.Length>0)
if (errors.Length > 0)
{
var first = errors[0];
var first = errors.FirstOrDefault(item => item.DefaultSeverity == DiagnosticSeverity.Error);
if (first == null)
{
first = errors[0];
}
var exception = new NatashaException(first.GetMessage());
exception.Diagnostics.AddRange(errors);
exception.Formatter = tree.ToString();
Expand All @@ -28,14 +32,18 @@ internal sealed class NatashaExceptionAnalyzer

internal static NatashaException GetCompileException(CSharpCompilation compilation, ImmutableArray<Diagnostic> errors)
{
var first = errors[0];
var first = errors.FirstOrDefault(item=>item.DefaultSeverity == DiagnosticSeverity.Error);
if (first == null)
{
first = errors[0];
}
var exception = new NatashaException(first.GetMessage());
exception.Diagnostics.AddRange(errors);
if (first.Location.SourceTree!=null)
if (first.Location.SourceTree != null)
{
exception.Formatter = first.Location.SourceTree.ToString();
}
else if(compilation.SyntaxTrees.Length > 0)
else if (compilation.SyntaxTrees.Length > 0)
{
exception.Formatter = compilation.SyntaxTrees[0].ToString();
}
Expand Down

0 comments on commit ae62595

Please sign in to comment.