Skip to content

Commit ef39f88

Browse files
author
William D Cossey
committed
Only include Errors in exception message.
1 parent 07eea7b commit ef39f88

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

RazorEngineCore/RazorEngine.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ private MemoryStream CreateAndCompileToStream(string templateSource, RazorEngine
108108

109109
if (!emitResult.Success)
110110
{
111-
List<Diagnostic> errors = emitResult.Diagnostics.ToList();
112-
113-
RazorEngineCompilationException exception = new RazorEngineCompilationException($"Unable to compile template: \n{string.Join("\n", errors)}")
111+
RazorEngineCompilationException exception = new RazorEngineCompilationException()
114112
{
115-
Errors = errors,
113+
Errors = emitResult.Diagnostics.ToList(),
116114
GeneratedCode = razorCSharpDocument.GeneratedCode
117115
};
118116

RazorEngineCore/RazorEngineCompilationException.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Runtime.Serialization;
45
using Microsoft.CodeAnalysis;
56

@@ -15,15 +16,14 @@ protected RazorEngineCompilationException(SerializationInfo info, StreamingConte
1516
{
1617
}
1718

18-
public RazorEngineCompilationException(string message) : base(message)
19-
{
20-
}
21-
22-
public RazorEngineCompilationException(string message, Exception innerException) : base(message, innerException)
19+
public RazorEngineCompilationException(Exception innerException) : base(null, innerException)
2320
{
2421
}
2522

2623
public List<Diagnostic> Errors { get; set; }
24+
2725
public string GeneratedCode { get; set; }
26+
27+
public override string Message => $"Unable to compile template: {string.Join("\n", Errors.Where(w => w.IsWarningAsError || w.Severity == DiagnosticSeverity.Error))}";
2828
}
2929
}

0 commit comments

Comments
 (0)