From 36cd47bc1f5a9e3b284a14377e9fb288dbb9008c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 7 Dec 2015 07:41:30 -0800 Subject: [PATCH] Move ICompilationException to Diagnostics Fixes #220 --- .../CompilationFailure.cs | 46 +++++++++++++ .../DiagnosticMessage.cs | 64 +++++++++++++++++++ .../ICompilationException.cs | 22 +++++++ .../DeveloperExceptionPageMiddleware.cs | 7 +- src/Microsoft.AspNet.Diagnostics/project.json | 2 +- 5 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.AspNet.Diagnostics.Abstractions/CompilationFailure.cs create mode 100644 src/Microsoft.AspNet.Diagnostics.Abstractions/DiagnosticMessage.cs create mode 100644 src/Microsoft.AspNet.Diagnostics.Abstractions/ICompilationException.cs diff --git a/src/Microsoft.AspNet.Diagnostics.Abstractions/CompilationFailure.cs b/src/Microsoft.AspNet.Diagnostics.Abstractions/CompilationFailure.cs new file mode 100644 index 0000000000..cd519d1b89 --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics.Abstractions/CompilationFailure.cs @@ -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 +{ + /// + /// Describes a failure compiling a specific file. + /// + public class CompilationFailure + { + public CompilationFailure(string sourceFilePath, string sourceFileContent, string compiledContent, IEnumerable messages) + { + SourceFilePath = sourceFilePath; + SourceFileContent = sourceFileContent; + CompiledContent = compiledContent; + Messages = messages; + } + + /// + /// Path of the file that produced the compilation failure. + /// + public string SourceFilePath { get; } + + /// + /// Contents of the file. + /// + public string SourceFileContent { get; } + + /// + /// Contents being compiled. + /// + /// + /// For templated files, the represents the original content and + /// represents the transformed content. This property can be null if + /// the exception is encountered during transformation. + /// + public string CompiledContent { get; } + + /// + /// Gets a sequence of produced as a result of compilation. + /// + public IEnumerable Messages { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics.Abstractions/DiagnosticMessage.cs b/src/Microsoft.AspNet.Diagnostics.Abstractions/DiagnosticMessage.cs new file mode 100644 index 0000000000..2fae1031ec --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics.Abstractions/DiagnosticMessage.cs @@ -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 +{ + /// + /// A single diagnostic message. + /// + 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; + } + + /// + /// Path of the file that produced the message. + /// + public string SourceFilePath { get; } + + /// + /// Gets the error message. + /// + public string Message { get; } + + /// + /// Gets the one-based line index for the start of the compilation error. + /// + public int StartLine { get; } + + /// + /// Gets the zero-based column index for the start of the compilation error. + /// + public int StartColumn { get; } + + /// + /// Gets the one-based line index for the end of the compilation error. + /// + public int EndLine { get; } + + /// + /// Gets the zero-based column index for the end of the compilation error. + /// + public int EndColumn { get; } + + /// + /// Gets the formatted error message. + /// + public string FormattedMessage { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics.Abstractions/ICompilationException.cs b/src/Microsoft.AspNet.Diagnostics.Abstractions/ICompilationException.cs new file mode 100644 index 0000000000..1a928baa8f --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics.Abstractions/ICompilationException.cs @@ -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 +{ + /// + /// Specifies the contract for an exception representing compilation failure. + /// + /// + /// This interface is implemented on exceptions thrown during compilation to enable consumers + /// to read compilation-related data out of the exception + /// + public interface ICompilationException + { + /// + /// Gets a sequence of with compilation failures. + /// + IEnumerable CompilationFailures { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageMiddleware.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageMiddleware.cs index 993712f118..c8578a7d6c 100644 --- a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageMiddleware.cs +++ b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageMiddleware.cs @@ -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) diff --git a/src/Microsoft.AspNet.Diagnostics/project.json b/src/Microsoft.AspNet.Diagnostics/project.json index 4761eeea45..34551c2775 100644 --- a/src/Microsoft.AspNet.Diagnostics/project.json +++ b/src/Microsoft.AspNet.Diagnostics/project.json @@ -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-*" },