Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
ASPNET_DETAILED_ERRORS, StandardOut, CoreClr StackTrace.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Sep 23, 2015
1 parent 70be7b2 commit 7c2c649
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public FailSafeStartupLoader(IServiceProvider services, IHostingEnvironment host
_nestedLoader = new StartupLoader(services, hostingEnv);
_services = services;
_runtimeEnv = runtimeEnv;
ShowDetailedErrors = hostingEnv.IsDevelopment();
ShowDetailedErrors = hostingEnv.IsDevelopment()
|| string.Equals("true", Environment.GetEnvironmentVariable("ASPNET_DETAILED_ERRORS"), StringComparison.OrdinalIgnoreCase);
}

// Internal for testing
Expand Down Expand Up @@ -86,6 +87,8 @@ internal class FailSafeStartup

public FailSafeStartup(bool showDetails, IRuntimeEnvironment env, Exception ex)
{
// Write errors to standard out so they can be retrieved when not in development mode.
Console.Out.WriteLine("Application startup exception: " + ex.ToString());
_errorBytes = StartupErrorUtilities.GenerateErrorHtml(showDetails, env, ex);
}

Expand Down
27 changes: 5 additions & 22 deletions src/Microsoft.AspNet.Hosting/Startup/StartupErrorUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public static byte[] GenerateErrorHtml(bool showDetails, IRuntimeEnvironment run
return Encoding.UTF8.GetBytes(String.Format(CultureInfo.InvariantCulture, _errorPageFormatString, builder, rawExceptionDetails, footer));
}


#if !DNXCORE50
private static string BuildCodeSnippetDiv(StackFrame frame)
{
string filename = frame.GetFileName();
Expand Down Expand Up @@ -178,7 +176,7 @@ private static string BuildMethodParametersUnescaped(MethodBase method)
return ((parameterType != null) ? PrettyPrintTypeName(parameterType) : "?") + " " + p.Name;
})) + ")";
}
#endif

private static void BuildCodeSnippetDiv(CompilationFailure failure,
StringBuilder builder,
ref int totalErrorsShown)
Expand Down Expand Up @@ -266,7 +264,6 @@ private static string GetResourceString(string name, bool escapeBraces = false)
return formatString;
}

#if !DNXCORE50
private static List<string> GetFailingCallSiteInFile(string filename, int failedLineNumber)
{
// We figure out the [first, last] range of lines to read from the file.
Expand Down Expand Up @@ -338,7 +335,7 @@ private static string PrettyPrintTypeName(Type t)
}

// Handle generic types
if (t.IsGenericType)
if (t.GetTypeInfo().IsGenericType)
{
// strip off the CLR generic type marker if it exists
int indexOfGenericTypeMarker = name.LastIndexOf('`');
Expand Down Expand Up @@ -378,7 +375,6 @@ private static void SplitTypeIntoPrefixAndFriendlyName(Type type, out string pre
prefix += ".";
}
}
#endif

private static string GenerateFooterEncoded(IRuntimeEnvironment environment)
{
Expand Down Expand Up @@ -417,15 +413,16 @@ private static string HtmlEncodeAndReplaceLineBreaks(string input)
.SelectMany(s => s.Split(new[] { '\r', '\n' }, StringSplitOptions.None))
.Select(HtmlEncoder.Default.HtmlEncode));
}
#if !DNXCORE50

private static void WriteException(Exception ex, StringBuilder builder, ref bool wasFailingCallSiteSourceWritten)
{
string inlineSourceDiv = null;

// First, build the stack trace
bool firstStackFrame = true;
StringBuilder stackTraceBuilder = new StringBuilder();
foreach (var frame in new StackTrace(ex, fNeedFileInfo: true).GetFrames() ?? Enumerable.Empty<StackFrame>())
bool needFileInfo = true;
foreach (var frame in new StackTrace(ex, needFileInfo).GetFrames() ?? Enumerable.Empty<StackFrame>())
{
if (!firstStackFrame)
{
Expand Down Expand Up @@ -453,20 +450,6 @@ private static void WriteException(Exception ex, StringBuilder builder, ref bool
inlineSourceDiv,
stackTraceBuilder);
}
#else
private static void WriteException(Exception ex, StringBuilder builder, ref bool wasFailingCallSiteSourceWritten)
{
// First, build the stack trace
string stackTrace = "<pre>" + HtmlEncodeAndReplaceLineBreaks(ex.StackTrace) + "</pre>";

// Finally, build the rest of the <div>
builder.AppendFormat(CultureInfo.InvariantCulture, _errorExceptionFormatString,
HtmlEncodeAndReplaceLineBreaks(ex.GetType().FullName),
HtmlEncodeAndReplaceLineBreaks(ex.Message),
null /* inlineSourceDiv */,
stackTrace);
}
#endif

private static void WriteRawExceptionDetails(string linkText, IEnumerable<string> lines, StringBuilder rawExceptionDetails)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNet.Hosting/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},
"dnxcore50": {
"dependencies": {
"System.Console": "4.0.0-beta-*"
"System.Console": "4.0.0-beta-*",
"System.Diagnostics.StackTrace": "4.0.1-beta-*"
}
}
}
Expand Down

0 comments on commit 7c2c649

Please sign in to comment.