Skip to content

Commit

Permalink
Only include Errors in exception message.
Browse files Browse the repository at this point in the history
  • Loading branch information
William D Cossey committed Apr 20, 2021
1 parent 07eea7b commit ef39f88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions RazorEngineCore/RazorEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ private MemoryStream CreateAndCompileToStream(string templateSource, RazorEngine

if (!emitResult.Success)
{
List<Diagnostic> errors = emitResult.Diagnostics.ToList();

RazorEngineCompilationException exception = new RazorEngineCompilationException($"Unable to compile template: \n{string.Join("\n", errors)}")
RazorEngineCompilationException exception = new RazorEngineCompilationException()
{
Errors = errors,
Errors = emitResult.Diagnostics.ToList(),
GeneratedCode = razorCSharpDocument.GeneratedCode
};

Expand Down
10 changes: 5 additions & 5 deletions RazorEngineCore/RazorEngineCompilationException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Microsoft.CodeAnalysis;

Expand All @@ -15,15 +16,14 @@ protected RazorEngineCompilationException(SerializationInfo info, StreamingConte
{
}

public RazorEngineCompilationException(string message) : base(message)
{
}

public RazorEngineCompilationException(string message, Exception innerException) : base(message, innerException)
public RazorEngineCompilationException(Exception innerException) : base(null, innerException)
{
}

public List<Diagnostic> Errors { get; set; }

public string GeneratedCode { get; set; }

public override string Message => $"Unable to compile template: {string.Join("\n", Errors.Where(w => w.IsWarningAsError || w.Severity == DiagnosticSeverity.Error))}";
}
}

0 comments on commit ef39f88

Please sign in to comment.