Skip to content

Commit

Permalink
Merge pull request #54 from wdcossey/wdcossey/improved-error-message
Browse files Browse the repository at this point in the history
A more descriptive error message.
  • Loading branch information
adoconnection authored May 26, 2021
2 parents 3a8ad7f + ef39f88 commit 0b1d02d
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: {errors.FirstOrDefault()}")
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 0b1d02d

Please sign in to comment.