Use Microsoft.Extensions.StackTrace.Sources

This commit is contained in:
Pranav K 2016-06-02 16:10:58 -07:00
parent 0025724433
commit b7c924b449
6 changed files with 198 additions and 225 deletions

View File

@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -16,7 +14,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using StackFrame = Microsoft.AspNetCore.Diagnostics.Views.StackFrame;
using Microsoft.Extensions.StackTrace.Sources;
namespace Microsoft.AspNetCore.Diagnostics
{
@ -27,10 +25,9 @@ namespace Microsoft.AspNetCore.Diagnostics
{
private readonly RequestDelegate _next;
private readonly DeveloperExceptionPageOptions _options;
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
private readonly ILogger _logger;
private readonly IFileProvider _fileProvider;
private readonly DiagnosticSource _diagnosticSource;
private readonly System.Diagnostics.DiagnosticSource _diagnosticSource;
/// <summary>
/// Initializes a new instance of the <see cref="DeveloperExceptionPageMiddleware"/> class
@ -45,7 +42,7 @@ namespace Microsoft.AspNetCore.Diagnostics
IOptions<DeveloperExceptionPageOptions> options,
ILoggerFactory loggerFactory,
IHostingEnvironment hostingEnvironment,
DiagnosticSource diagnosticSource)
System.Diagnostics.DiagnosticSource diagnosticSource)
{
if (next == null)
{
@ -122,7 +119,7 @@ namespace Microsoft.AspNetCore.Diagnostics
private Task DisplayCompilationException(
HttpContext context,
ICompilationException compilationException)
ICompilationException compilationException)
{
var model = new CompilationErrorPageModel
{
@ -187,75 +184,40 @@ namespace Microsoft.AspNetCore.Diagnostics
{
for (var scan = ex; scan != null; scan = scan.InnerException)
{
var stackTrace = ex.StackTrace;
yield return new ErrorDetails
{
Error = scan,
StackFrames = StackFrames(scan)
StackFrames = StackTraceHelper.GetFrames(ex)
.Select(frame => GetStackFrame(frame.Method, frame.FilePath, frame.LineNumber))
};
}
}
private IEnumerable<StackFrame> StackFrames(Exception ex)
{
var stackTrace = ex.StackTrace;
if (!string.IsNullOrEmpty(stackTrace))
{
var heap = new Chunk { Text = stackTrace + Environment.NewLine, End = stackTrace.Length + Environment.NewLine.Length };
for (var line = heap.Advance(Environment.NewLine); line.HasValue; line = heap.Advance(Environment.NewLine))
{
yield return StackFrame(line);
}
}
}
private StackFrame StackFrame(Chunk line)
{
line.Advance(" at ");
string function = line.Advance(" in ").ToString();
//exception message line format differences in .net and mono
//On .net : at ConsoleApplication.Program.Main(String[] args) in D:\Program.cs:line 16
//On Mono : at ConsoleApplication.Program.Main(String[] args) in d:\Program.cs:16
string file = !IsMono ?
line.Advance(":line ").ToString() :
line.Advance(":").ToString();
int lineNumber = line.ToInt32();
if (string.IsNullOrEmpty(file))
{
return GetStackFrame(
// Handle stack trace lines like
// "--- End of stack trace from previous location where exception from thrown ---"
string.IsNullOrEmpty(function) ? line.ToString() : function,
file: string.Empty,
lineNumber: 0);
}
else
{
return GetStackFrame(function, file, lineNumber);
}
};
}
// make it internal to enable unit testing
internal StackFrame GetStackFrame(string function, string file, int lineNumber)
internal StackFrame GetStackFrame(string method, string filePath, int lineNumber)
{
var frame = new StackFrame { Function = function, File = file, Line = lineNumber };
if (string.IsNullOrEmpty(file))
var stackFrame = new StackFrame
{
return frame;
Function = method,
File = filePath,
Line = lineNumber
};
if (string.IsNullOrEmpty(stackFrame.File))
{
return stackFrame;
}
IEnumerable<string> lines = null;
if (File.Exists(file))
if (File.Exists(stackFrame.File))
{
lines = File.ReadLines(file);
lines = File.ReadLines(stackFrame.File);
}
else
{
// Handle relative paths and embedded files
var fileInfo = _fileProvider.GetFileInfo(file);
var fileInfo = _fileProvider.GetFileInfo(stackFrame.File);
if (fileInfo.Exists)
{
// ReadLines doesn't accept a stream. Use ReadLines as its more efficient
@ -273,10 +235,10 @@ namespace Microsoft.AspNetCore.Diagnostics
if (lines != null)
{
ReadFrameContent(frame, lines, lineNumber, lineNumber);
ReadFrameContent(stackFrame, lines, stackFrame.Line, stackFrame.Line);
}
return frame;
return stackFrame;
}
// make it internal to enable unit testing
@ -319,42 +281,5 @@ namespace Microsoft.AspNetCore.Diagnostics
}
}
}
internal class Chunk
{
public string Text { get; set; }
public int Start { get; set; }
public int End { get; set; }
public bool HasValue => Text != null;
public Chunk Advance(string delimiter)
{
int indexOf = HasValue ? Text.IndexOf(delimiter, Start, End - Start, StringComparison.Ordinal) : -1;
if (indexOf < 0)
{
return new Chunk();
}
var chunk = new Chunk { Text = Text, Start = Start, End = indexOf };
Start = indexOf + delimiter.Length;
return chunk;
}
public override string ToString()
{
return HasValue ? Text.Substring(Start, End - Start) : string.Empty;
}
public int ToInt32()
{
int value;
return HasValue && int.TryParse(
Text.Substring(Start, End - Start),
NumberStyles.Integer,
CultureInfo.InvariantCulture,
out value) ? value : 0;
}
}
}
}

View File

@ -124,22 +124,17 @@ WriteAttributeValue("", 512, CultureInfo.CurrentUICulture.TwoLetterISOLanguageNa
#line 35 "ErrorPage.cshtml"
StackFrame firstFrame = null;
firstFrame = errorDetail.StackFrames.FirstOrDefault();
var firstFrame = errorDetail.StackFrames.FirstOrDefault();
if (firstFrame != null)
{
location = firstFrame.Function;
}/* TODO: TargetSite is not defined
else if (errorDetail.Error.TargetSite != null && errorDetail.Error.TargetSite.DeclaringType != null)
{
location = errorDetail.Error.TargetSite.DeclaringType.FullName + "." + errorDetail.Error.TargetSite.Name;
}*/
}
#line default
#line hidden
#line 46 "ErrorPage.cshtml"
#line 41 "ErrorPage.cshtml"
if (!string.IsNullOrEmpty(location) && firstFrame != null && !string.IsNullOrEmpty(firstFrame.File))
{
@ -148,33 +143,33 @@ WriteAttributeValue("", 512, CultureInfo.CurrentUICulture.TwoLetterISOLanguageNa
#line hidden
WriteLiteral(" <p class=\"location\">");
#line 49 "ErrorPage.cshtml"
#line 44 "ErrorPage.cshtml"
Write(location);
#line default
#line hidden
WriteLiteral(" in <code");
BeginWriteAttribute("title", " title=\"", 1882, "\"", 1906, 1);
#line 49 "ErrorPage.cshtml"
WriteAttributeValue("", 1890, firstFrame.File, 1890, 16, false);
BeginWriteAttribute("title", " title=\"", 1520, "\"", 1544, 1);
#line 44 "ErrorPage.cshtml"
WriteAttributeValue("", 1528, firstFrame.File, 1528, 16, false);
#line default
#line hidden
EndWriteAttribute();
WriteLiteral(">");
#line 49 "ErrorPage.cshtml"
#line 44 "ErrorPage.cshtml"
Write(System.IO.Path.GetFileName(firstFrame.File));
#line default
#line hidden
WriteLiteral("</code>, line ");
#line 49 "ErrorPage.cshtml"
#line 44 "ErrorPage.cshtml"
Write(firstFrame.Line);
#line default
#line hidden
WriteLiteral("</p>\r\n");
#line 50 "ErrorPage.cshtml"
#line 45 "ErrorPage.cshtml"
}
else if (!string.IsNullOrEmpty(location))
{
@ -183,13 +178,13 @@ WriteAttributeValue("", 1890, firstFrame.File, 1890, 16, false);
#line hidden
WriteLiteral(" <p class=\"location\">");
#line 53 "ErrorPage.cshtml"
#line 48 "ErrorPage.cshtml"
Write(location);
#line default
#line hidden
WriteLiteral("</p>\r\n");
#line 54 "ErrorPage.cshtml"
#line 49 "ErrorPage.cshtml"
}
else
{
@ -198,13 +193,13 @@ WriteAttributeValue("", 1890, firstFrame.File, 1890, 16, false);
#line hidden
WriteLiteral(" <p class=\"location\">");
#line 57 "ErrorPage.cshtml"
#line 52 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_UnknownLocation);
#line default
#line hidden
WriteLiteral("</p>\r\n");
#line 58 "ErrorPage.cshtml"
#line 53 "ErrorPage.cshtml"
}
}
@ -212,44 +207,44 @@ WriteAttributeValue("", 1890, firstFrame.File, 1890, 16, false);
#line hidden
WriteLiteral(" <ul id=\"header\">\r\n <li id=\"stack\" tabindex=\"1\" class=\"selected\">\r\n ");
#line 62 "ErrorPage.cshtml"
#line 57 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_StackButton);
#line default
#line hidden
WriteLiteral("\r\n </li>\r\n <li id=\"query\" tabindex=\"2\">\r\n ");
#line 65 "ErrorPage.cshtml"
#line 60 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_QueryButton);
#line default
#line hidden
WriteLiteral("\r\n </li>\r\n <li id=\"cookies\" tabindex=\"3\">\r\n ");
#line 68 "ErrorPage.cshtml"
#line 63 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_CookiesButton);
#line default
#line hidden
WriteLiteral("\r\n </li>\r\n <li id=\"headers\" tabindex=\"4\">\r\n ");
#line 71 "ErrorPage.cshtml"
#line 66 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_HeadersButton);
#line default
#line hidden
WriteLiteral("\r\n </li>\r\n </ul>\r\n\r\n <div id=\"stackpage\" class=\"page\">\r\n <ul>\r\n");
#line 77 "ErrorPage.cshtml"
#line 72 "ErrorPage.cshtml"
#line default
#line hidden
#line 77 "ErrorPage.cshtml"
#line 72 "ErrorPage.cshtml"
int tabIndex = 6;
#line default
#line hidden
WriteLiteral(" ");
#line 78 "ErrorPage.cshtml"
#line 73 "ErrorPage.cshtml"
foreach (var errorDetail in Model.ErrorDetails)
{
@ -257,25 +252,25 @@ WriteAttributeValue("", 1890, firstFrame.File, 1890, 16, false);
#line hidden
WriteLiteral(" <li>\r\n <h2 class=\"stackerror\">");
#line 81 "ErrorPage.cshtml"
#line 76 "ErrorPage.cshtml"
Write(errorDetail.Error.GetType().Name);
#line default
#line hidden
WriteLiteral(": ");
#line 81 "ErrorPage.cshtml"
#line 76 "ErrorPage.cshtml"
Write(errorDetail.Error.Message);
#line default
#line hidden
WriteLiteral("</h2>\r\n <ul>\r\n");
#line 83 "ErrorPage.cshtml"
#line 78 "ErrorPage.cshtml"
#line default
#line hidden
#line 83 "ErrorPage.cshtml"
#line 78 "ErrorPage.cshtml"
foreach (var frame in errorDetail.StackFrames)
{
@ -283,28 +278,28 @@ WriteAttributeValue("", 1890, firstFrame.File, 1890, 16, false);
#line hidden
WriteLiteral(" <li class=\"frame\"");
BeginWriteAttribute("tabindex", " tabindex=\"", 3310, "\"", 3330, 1);
#line 85 "ErrorPage.cshtml"
WriteAttributeValue("", 3321, tabIndex, 3321, 9, false);
BeginWriteAttribute("tabindex", " tabindex=\"", 2948, "\"", 2968, 1);
#line 80 "ErrorPage.cshtml"
WriteAttributeValue("", 2959, tabIndex, 2959, 9, false);
#line default
#line hidden
EndWriteAttribute();
WriteLiteral(">\r\n");
#line 86 "ErrorPage.cshtml"
#line 81 "ErrorPage.cshtml"
#line default
#line hidden
#line 86 "ErrorPage.cshtml"
#line 81 "ErrorPage.cshtml"
tabIndex++;
#line default
#line hidden
WriteLiteral(" ");
#line 87 "ErrorPage.cshtml"
#line 82 "ErrorPage.cshtml"
if (string.IsNullOrEmpty(frame.File))
{
@ -312,13 +307,13 @@ WriteAttributeValue("", 3321, tabIndex, 3321, 9, false);
#line hidden
WriteLiteral(" <h3>");
#line 89 "ErrorPage.cshtml"
#line 84 "ErrorPage.cshtml"
Write(frame.Function);
#line default
#line hidden
WriteLiteral("</h3>\r\n");
#line 90 "ErrorPage.cshtml"
#line 85 "ErrorPage.cshtml"
}
else
{
@ -327,40 +322,40 @@ WriteAttributeValue("", 3321, tabIndex, 3321, 9, false);
#line hidden
WriteLiteral(" <h3>");
#line 93 "ErrorPage.cshtml"
#line 88 "ErrorPage.cshtml"
Write(frame.Function);
#line default
#line hidden
WriteLiteral(" in <code");
BeginWriteAttribute("title", " title=\"", 3725, "\"", 3744, 1);
#line 93 "ErrorPage.cshtml"
WriteAttributeValue("", 3733, frame.File, 3733, 11, false);
BeginWriteAttribute("title", " title=\"", 3363, "\"", 3382, 1);
#line 88 "ErrorPage.cshtml"
WriteAttributeValue("", 3371, frame.File, 3371, 11, false);
#line default
#line hidden
EndWriteAttribute();
WriteLiteral(">");
#line 93 "ErrorPage.cshtml"
#line 88 "ErrorPage.cshtml"
Write(System.IO.Path.GetFileName(frame.File));
#line default
#line hidden
WriteLiteral("</code></h3>\r\n");
#line 94 "ErrorPage.cshtml"
#line 89 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral("\r\n");
#line 96 "ErrorPage.cshtml"
#line 91 "ErrorPage.cshtml"
#line default
#line hidden
#line 96 "ErrorPage.cshtml"
#line 91 "ErrorPage.cshtml"
if (frame.Line != 0 && frame.ContextCode.Any())
{
@ -368,13 +363,13 @@ WriteAttributeValue("", 3733, frame.File, 3733, 11, false);
#line hidden
WriteLiteral(" <div class=\"source\">\r\n");
#line 99 "ErrorPage.cshtml"
#line 94 "ErrorPage.cshtml"
#line default
#line hidden
#line 99 "ErrorPage.cshtml"
#line 94 "ErrorPage.cshtml"
if (frame.PreContextCode.Any())
{
@ -382,21 +377,21 @@ WriteAttributeValue("", 3733, frame.File, 3733, 11, false);
#line hidden
WriteLiteral(" <ol");
BeginWriteAttribute("start", " start=\"", 4175, "\"", 4204, 1);
#line 101 "ErrorPage.cshtml"
WriteAttributeValue("", 4183, frame.PreContextLine, 4183, 21, false);
BeginWriteAttribute("start", " start=\"", 3813, "\"", 3842, 1);
#line 96 "ErrorPage.cshtml"
WriteAttributeValue("", 3821, frame.PreContextLine, 3821, 21, false);
#line default
#line hidden
EndWriteAttribute();
WriteLiteral(" class=\"collapsible\">\r\n");
#line 102 "ErrorPage.cshtml"
#line 97 "ErrorPage.cshtml"
#line default
#line hidden
#line 102 "ErrorPage.cshtml"
#line 97 "ErrorPage.cshtml"
foreach (var line in frame.PreContextCode)
{
@ -404,41 +399,41 @@ WriteAttributeValue("", 4183, frame.PreContextLine, 4183, 21, false);
#line hidden
WriteLiteral(" <li><span>");
#line 104 "ErrorPage.cshtml"
#line 99 "ErrorPage.cshtml"
Write(line);
#line default
#line hidden
WriteLiteral("</span></li>\r\n");
#line 105 "ErrorPage.cshtml"
#line 100 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ol>\r\n");
#line 107 "ErrorPage.cshtml"
#line 102 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral("\r\n <ol");
BeginWriteAttribute("start", " start=\"", 4643, "\"", 4662, 1);
#line 109 "ErrorPage.cshtml"
WriteAttributeValue("", 4651, frame.Line, 4651, 11, false);
BeginWriteAttribute("start", " start=\"", 4281, "\"", 4300, 1);
#line 104 "ErrorPage.cshtml"
WriteAttributeValue("", 4289, frame.Line, 4289, 11, false);
#line default
#line hidden
EndWriteAttribute();
WriteLiteral(" class=\"highlight\">\r\n");
#line 110 "ErrorPage.cshtml"
#line 105 "ErrorPage.cshtml"
#line default
#line hidden
#line 110 "ErrorPage.cshtml"
#line 105 "ErrorPage.cshtml"
foreach (var line in frame.ContextCode)
{
@ -446,26 +441,26 @@ WriteAttributeValue("", 4651, frame.Line, 4651, 11, false);
#line hidden
WriteLiteral(" <li><span>");
#line 112 "ErrorPage.cshtml"
#line 107 "ErrorPage.cshtml"
Write(line);
#line default
#line hidden
WriteLiteral("</span></li>\r\n");
#line 113 "ErrorPage.cshtml"
#line 108 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ol>\r\n\r\n");
#line 116 "ErrorPage.cshtml"
#line 111 "ErrorPage.cshtml"
#line default
#line hidden
#line 116 "ErrorPage.cshtml"
#line 111 "ErrorPage.cshtml"
if (frame.PostContextCode.Any())
{
@ -473,21 +468,21 @@ WriteAttributeValue("", 4651, frame.Line, 4651, 11, false);
#line hidden
WriteLiteral(" <ol");
BeginWriteAttribute("start", " start=\'", 5155, "\'", 5180, 1);
#line 118 "ErrorPage.cshtml"
WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
BeginWriteAttribute("start", " start=\'", 4793, "\'", 4818, 1);
#line 113 "ErrorPage.cshtml"
WriteAttributeValue("", 4801, frame.Line + 1, 4801, 17, false);
#line default
#line hidden
EndWriteAttribute();
WriteLiteral(" class=\"collapsible\">\r\n");
#line 119 "ErrorPage.cshtml"
#line 114 "ErrorPage.cshtml"
#line default
#line hidden
#line 119 "ErrorPage.cshtml"
#line 114 "ErrorPage.cshtml"
foreach (var line in frame.PostContextCode)
{
@ -495,34 +490,34 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <li><span>");
#line 121 "ErrorPage.cshtml"
#line 116 "ErrorPage.cshtml"
Write(line);
#line default
#line hidden
WriteLiteral("</span></li>\r\n");
#line 122 "ErrorPage.cshtml"
#line 117 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ol>\r\n");
#line 124 "ErrorPage.cshtml"
#line 119 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </div>\r\n");
#line 126 "ErrorPage.cshtml"
#line 121 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </li>\r\n");
#line 128 "ErrorPage.cshtml"
#line 123 "ErrorPage.cshtml"
}
#line default
@ -538,26 +533,26 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
</div>
<div id=""rawException"" style=""display:none"">
<pre>");
#line 138 "ErrorPage.cshtml"
#line 133 "ErrorPage.cshtml"
Write(errorDetail.Error.ToString());
#line default
#line hidden
WriteLiteral("</pre>\r\n </div>\r\n </div>\r\n </li>\r\n");
#line 142 "ErrorPage.cshtml"
#line 137 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ul>\r\n </div>\r\n\r\n <div id=\"querypage\" class=\"page\">\r\n");
#line 147 "ErrorPage.cshtml"
#line 142 "ErrorPage.cshtml"
#line default
#line hidden
#line 147 "ErrorPage.cshtml"
#line 142 "ErrorPage.cshtml"
if (Model.Query.Any())
{
@ -565,25 +560,25 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <table>\r\n <thead>\r\n <tr>\r\n <th>");
#line 152 "ErrorPage.cshtml"
#line 147 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_VariableColumn);
#line default
#line hidden
WriteLiteral("</th>\r\n <th>");
#line 153 "ErrorPage.cshtml"
#line 148 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_ValueColumn);
#line default
#line hidden
WriteLiteral("</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n");
#line 157 "ErrorPage.cshtml"
#line 152 "ErrorPage.cshtml"
#line default
#line hidden
#line 157 "ErrorPage.cshtml"
#line 152 "ErrorPage.cshtml"
foreach (var kv in Model.Query.OrderBy(kv => kv.Key))
{
foreach (var v in kv.Value)
@ -593,19 +588,19 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <tr>\r\n <td>");
#line 162 "ErrorPage.cshtml"
#line 157 "ErrorPage.cshtml"
Write(kv.Key);
#line default
#line hidden
WriteLiteral("</td>\r\n <td>");
#line 163 "ErrorPage.cshtml"
#line 158 "ErrorPage.cshtml"
Write(v);
#line default
#line hidden
WriteLiteral("</td>\r\n </tr>\r\n");
#line 165 "ErrorPage.cshtml"
#line 160 "ErrorPage.cshtml"
}
}
@ -613,7 +608,7 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" </tbody>\r\n </table>\r\n");
#line 169 "ErrorPage.cshtml"
#line 164 "ErrorPage.cshtml"
}
else
{
@ -622,26 +617,26 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <p>");
#line 172 "ErrorPage.cshtml"
#line 167 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_NoQueryStringData);
#line default
#line hidden
WriteLiteral("</p>\r\n");
#line 173 "ErrorPage.cshtml"
#line 168 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </div>\r\n\r\n <div id=\"cookiespage\" class=\"page\">\r\n");
#line 177 "ErrorPage.cshtml"
#line 172 "ErrorPage.cshtml"
#line default
#line hidden
#line 177 "ErrorPage.cshtml"
#line 172 "ErrorPage.cshtml"
if (Model.Cookies.Any())
{
@ -649,25 +644,25 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <table>\r\n <thead>\r\n <tr>\r\n <th>");
#line 182 "ErrorPage.cshtml"
#line 177 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_VariableColumn);
#line default
#line hidden
WriteLiteral("</th>\r\n <th>");
#line 183 "ErrorPage.cshtml"
#line 178 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_ValueColumn);
#line default
#line hidden
WriteLiteral("</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n");
#line 187 "ErrorPage.cshtml"
#line 182 "ErrorPage.cshtml"
#line default
#line hidden
#line 187 "ErrorPage.cshtml"
#line 182 "ErrorPage.cshtml"
foreach (var kv in Model.Cookies.OrderBy(kv => kv.Key))
{
@ -675,26 +670,26 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <tr>\r\n <td>");
#line 190 "ErrorPage.cshtml"
#line 185 "ErrorPage.cshtml"
Write(kv.Key);
#line default
#line hidden
WriteLiteral("</td>\r\n <td>");
#line 191 "ErrorPage.cshtml"
#line 186 "ErrorPage.cshtml"
Write(kv.Value);
#line default
#line hidden
WriteLiteral("</td>\r\n </tr>\r\n");
#line 193 "ErrorPage.cshtml"
#line 188 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </tbody>\r\n </table>\r\n");
#line 196 "ErrorPage.cshtml"
#line 191 "ErrorPage.cshtml"
}
else
{
@ -703,26 +698,26 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <p>");
#line 199 "ErrorPage.cshtml"
#line 194 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_NoCookieData);
#line default
#line hidden
WriteLiteral("</p>\r\n");
#line 200 "ErrorPage.cshtml"
#line 195 "ErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </div>\r\n <div id=\"headerspage\" class=\"page\">\r\n");
#line 203 "ErrorPage.cshtml"
#line 198 "ErrorPage.cshtml"
#line default
#line hidden
#line 203 "ErrorPage.cshtml"
#line 198 "ErrorPage.cshtml"
if (Model.Headers.Any())
{
@ -730,25 +725,25 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <table>\r\n <thead>\r\n <tr>\r\n <th>");
#line 208 "ErrorPage.cshtml"
#line 203 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_VariableColumn);
#line default
#line hidden
WriteLiteral("</th>\r\n <th>");
#line 209 "ErrorPage.cshtml"
#line 204 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_ValueColumn);
#line default
#line hidden
WriteLiteral("</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n");
#line 213 "ErrorPage.cshtml"
#line 208 "ErrorPage.cshtml"
#line default
#line hidden
#line 213 "ErrorPage.cshtml"
#line 208 "ErrorPage.cshtml"
foreach (var kv in Model.Headers.OrderBy(kv => kv.Key))
{
foreach (var v in kv.Value)
@ -758,19 +753,19 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <tr>\r\n <td>");
#line 218 "ErrorPage.cshtml"
#line 213 "ErrorPage.cshtml"
Write(kv.Key);
#line default
#line hidden
WriteLiteral("</td>\r\n <td>");
#line 219 "ErrorPage.cshtml"
#line 214 "ErrorPage.cshtml"
Write(v);
#line default
#line hidden
WriteLiteral("</td>\r\n </tr>\r\n");
#line 221 "ErrorPage.cshtml"
#line 216 "ErrorPage.cshtml"
}
}
@ -778,7 +773,7 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" </tbody>\r\n </table>\r\n");
#line 225 "ErrorPage.cshtml"
#line 220 "ErrorPage.cshtml"
}
else
{
@ -787,13 +782,13 @@ WriteAttributeValue("", 5163, frame.Line + 1, 5163, 17, false);
#line hidden
WriteLiteral(" <p>");
#line 228 "ErrorPage.cshtml"
#line 223 "ErrorPage.cshtml"
Write(Resources.ErrorPageHtml_NoHeaderData);
#line default
#line hidden
WriteLiteral("</p>\r\n");
#line 229 "ErrorPage.cshtml"
#line 224 "ErrorPage.cshtml"
}
#line default

View File

@ -33,16 +33,11 @@
{
<div class="titleerror">@errorDetail.Error.GetType().Name: @{ Output.Write(HtmlEncodeAndReplaceLineBreaks(errorDetail.Error.Message)); }</div>
@{
StackFrame firstFrame = null;
firstFrame = errorDetail.StackFrames.FirstOrDefault();
var firstFrame = errorDetail.StackFrames.FirstOrDefault();
if (firstFrame != null)
{
location = firstFrame.Function;
}/* TODO: TargetSite is not defined
else if (errorDetail.Error.TargetSite != null && errorDetail.Error.TargetSite.DeclaringType != null)
{
location = errorDetail.Error.TargetSite.DeclaringType.FullName + "." + errorDetail.Error.TargetSite.Name;
}*/
}
}
if (!string.IsNullOrEmpty(location) && firstFrame != null && !string.IsNullOrEmpty(firstFrame.File))
{

View File

@ -0,0 +1,54 @@
// 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;
using System.Linq;
namespace Microsoft.AspNetCore.Diagnostics.Views
{
/// <summary>
/// Detailed exception stack information used to generate a view
/// </summary>
public class StackFrameInfo
{
/// <summary>
/// Function containing instruction
/// </summary>
public string Function { get; set; }
/// <summary>
/// File containing the instruction
/// </summary>
public string File { get; set; }
/// <summary>
/// The line number of the instruction
/// </summary>
public int Line { get; set; }
/// <summary>
/// The line preceeding the frame line
/// </summary>
public int PreContextLine { get; set; }
/// <summary>
/// Lines of code before the actual error line(s).
/// </summary>
public IEnumerable<string> PreContextCode { get; set; } = Enumerable.Empty<string>();
/// <summary>
/// Line(s) of code responsible for the error.
/// </summary>
public IEnumerable<string> ContextCode { get; set; } = Enumerable.Empty<string>();
/// <summary>
/// Lines of code after the actual error line(s).
/// </summary>
public IEnumerable<string> PostContextCode { get; set; } = Enumerable.Empty<string>();
/// <summary>
/// Specific error details for this stack frame.
/// </summary>
public string ErrorDetails { get; set; }
}
}

View File

@ -31,12 +31,18 @@
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
"Microsoft.Extensions.Options": "1.0.0-*",
"System.Diagnostics.DiagnosticSource": "4.0.0-*"
"Microsoft.Extensions.StackTrace.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"System.Diagnostics.DiagnosticSource": "4.0.0-*",
"System.Reflection.Metadata": "1.3.0-*"
},
"frameworks": {
"net451": {},
"netstandard1.3": {
"netstandard1.5": {
"dependencies": {
"System.Diagnostics.StackTrace": "4.0.1-*",
"System.Reflection.Extensions": "4.0.1-*"
}
}

View File

@ -8,7 +8,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -16,14 +15,13 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Xunit;
using StackFrame = Microsoft.AspNetCore.Diagnostics.Views.StackFrame;
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Diagnostics
{
@ -273,7 +271,7 @@ namespace Microsoft.AspNetCore.Diagnostics
{
// Arrange
var middleware = GetErrorPageMiddleware();
var stackFrame = new StackFrame();
var stackFrame = new Views.StackFrame();
// Act
middleware.ReadFrameContent(