Move ICompilationException to Diagnostics

Fixes #220
This commit is contained in:
Pranav K 2015-12-07 07:41:30 -08:00
parent 7a2c20649b
commit 36cd47bc1f
5 changed files with 137 additions and 4 deletions

View File

@ -0,0 +1,46 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// Describes a failure compiling a specific file.
/// </summary>
public class CompilationFailure
{
public CompilationFailure(string sourceFilePath, string sourceFileContent, string compiledContent, IEnumerable<DiagnosticMessage> messages)
{
SourceFilePath = sourceFilePath;
SourceFileContent = sourceFileContent;
CompiledContent = compiledContent;
Messages = messages;
}
/// <summary>
/// Path of the file that produced the compilation failure.
/// </summary>
public string SourceFilePath { get; }
/// <summary>
/// Contents of the file.
/// </summary>
public string SourceFileContent { get; }
/// <summary>
/// Contents being compiled.
/// </summary>
/// <remarks>
/// For templated files, the <see cref="SourceFileContent"/> represents the original content and
/// <see cref="CompiledContent"/> represents the transformed content. This property can be null if
/// the exception is encountered during transformation.
/// </remarks>
public string CompiledContent { get; }
/// <summary>
/// Gets a sequence of <see cref="DiagnosticMessage"/> produced as a result of compilation.
/// </summary>
public IEnumerable<DiagnosticMessage> Messages { get; }
}
}

View File

@ -0,0 +1,64 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// A single diagnostic message.
/// </summary>
public class DiagnosticMessage
{
public DiagnosticMessage(
string message,
string formattedMessage,
string filePath,
int startLine,
int startColumn,
int endLine,
int endColumn)
{
Message = message;
SourceFilePath = filePath;
StartLine = startLine;
EndLine = endLine;
StartColumn = startColumn;
EndColumn = endColumn;
FormattedMessage = formattedMessage;
}
/// <summary>
/// Path of the file that produced the message.
/// </summary>
public string SourceFilePath { get; }
/// <summary>
/// Gets the error message.
/// </summary>
public string Message { get; }
/// <summary>
/// Gets the one-based line index for the start of the compilation error.
/// </summary>
public int StartLine { get; }
/// <summary>
/// Gets the zero-based column index for the start of the compilation error.
/// </summary>
public int StartColumn { get; }
/// <summary>
/// Gets the one-based line index for the end of the compilation error.
/// </summary>
public int EndLine { get; }
/// <summary>
/// Gets the zero-based column index for the end of the compilation error.
/// </summary>
public int EndColumn { get; }
/// <summary>
/// Gets the formatted error message.
/// </summary>
public string FormattedMessage { get; }
}
}

View File

@ -0,0 +1,22 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// Specifies the contract for an exception representing compilation failure.
/// </summary>
/// <remarks>
/// This interface is implemented on exceptions thrown during compilation to enable consumers
/// to read compilation-related data out of the exception
/// </remarks>
public interface ICompilationException
{
/// <summary>
/// Gets a sequence of <see cref="CompilationFailure"/> with compilation failures.
/// </summary>
IEnumerable<CompilationFailure> CompilationFailures { get; }
}
}

View File

@ -12,7 +12,6 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.CompilationAbstractions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;
using StackFrame = Microsoft.AspNet.Diagnostics.Views.StackFrame;
@ -116,7 +115,8 @@ namespace Microsoft.AspNet.Diagnostics
return DisplayRuntimeException(context, ex);
}
private Task DisplayCompilationException(HttpContext context,
private Task DisplayCompilationException(
HttpContext context,
ICompilationException compilationException)
{
var model = new CompilationErrorPageModel
@ -131,7 +131,8 @@ namespace Microsoft.AspNet.Diagnostics
{
StackFrames = stackFrames
};
var fileContent = compilationFailure.SourceFileContent
var fileContent = compilationFailure
.SourceFileContent
.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
foreach (var item in compilationFailure.Messages)

View File

@ -14,9 +14,9 @@
"Microsoft.AspNet.FileProviders.Physical": "1.0.0-*",
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
"Microsoft.Extensions.CompilationAbstractions": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
"Microsoft.Extensions.OptionsModel": "1.0.0-*",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
"Microsoft.Extensions.WebEncoders": "1.0.0-*",
"System.Diagnostics.DiagnosticSource": "4.0.0-*"
},