Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit a36039f
Author: Rob Fletcher <robert.w.fletcher@gmail.com>
Date:   Tue Jun 21 09:25:05 2011 +0100

    merged in error page changes

commit cf43daf
Merge: 7f9ce99 2431a4e
Author: Rob Fletcher <robert.w.fletcher@gmail.com>
Date:   Tue Jun 21 09:04:24 2011 +0100

    Merge branch 'master' into error-styling

commit 7f9ce99
Merge: 9e9bdf0 2729529
Author: Rob Fletcher <robert.w.fletcher@gmail.com>
Date:   Fri Jun 17 19:20:50 2011 +0100

    Merge branch 'master' into error-styling

commit 9e9bdf0
Author: Rob Fletcher <robert.w.fletcher@gmail.com>
Date:   Fri Jun 17 07:44:00 2011 +0100

    use definition list for error details

commit 06ab871
Merge: 2f17272 a973217
Author: Rob Fletcher <robert.w.fletcher@gmail.com>
Date:   Thu Jun 16 21:47:02 2011 +0100

    Merge branch 'master' into error-styling

    Conflicts:
    	grails-plugin-gsp/src/main/groovy/org/codehaus/groovy/grails/plugins/web/taglib/RenderTagLib.groovy

commit 2f17272
Author: Rob Fletcher <robert.w.fletcher@gmail.com>
Date:   Thu Jun 16 21:43:58 2011 +0100

    add a margin above the page footer

commit fd8d59d
Author: Rob Fletcher <robert.w.fletcher@gmail.com>
Date:   Thu Jun 16 21:43:31 2011 +0100

    simplify & correct some markup in error output
  • Loading branch information
robfletcher committed Jun 21, 2011
1 parent 2431a4e commit da90fae
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 63 deletions.
Expand Up @@ -24,6 +24,7 @@ import grails.util.GrailsNameUtils
import groovy.text.Template import groovy.text.Template
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import javax.servlet.ServletConfig import javax.servlet.ServletConfig
import org.apache.commons.lang.WordUtils
import org.codehaus.groovy.grails.commons.GrailsDomainClass import org.codehaus.groovy.grails.commons.GrailsDomainClass
import org.codehaus.groovy.grails.io.support.GrailsResourceUtils import org.codehaus.groovy.grails.io.support.GrailsResourceUtils
import org.codehaus.groovy.grails.plugins.BinaryGrailsPlugin import org.codehaus.groovy.grails.plugins.BinaryGrailsPlugin
Expand All @@ -42,6 +43,7 @@ import org.codehaus.groovy.grails.web.sitemesh.GSPSitemeshPage
import org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter import org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter
import org.codehaus.groovy.grails.web.util.StreamCharBuffer import org.codehaus.groovy.grails.web.util.StreamCharBuffer
import org.codehaus.groovy.grails.web.util.WebUtils import org.codehaus.groovy.grails.web.util.WebUtils
import org.springframework.http.HttpStatus
import org.springframework.util.StringUtils import org.springframework.util.StringUtils


/** /**
Expand Down Expand Up @@ -698,26 +700,31 @@ class RenderTagLib implements RequestConstants {
} }


def currentOut = out def currentOut = out
currentOut << """<h2>Error ${request.'javax.servlet.error.status_code'}</h2> currentOut << """<h1>Error ${prettyPrintStatus(request.'javax.servlet.error.status_code')}</h1>
<div class="errors"> <dl class="error-details">
<strong>URI:</strong> ${request.forwardURI ?: request.'javax.servlet.error.request_uri'}<br/> <dt>URI</dt><dd>${request.forwardURI ?: request.'javax.servlet.error.request_uri'}</dd>
""" """


def root = GrailsExceptionResolver.getRootCause(exception) def root = GrailsExceptionResolver.getRootCause(exception)
currentOut << "<strong>Message:</strong> ${exception.message?.encodeAsHTML()} <br />" currentOut << "<dt>Class</dt><dd>${root?.getClass()?.name ?: exception.getClass().name}</dd>"
currentOut << "<dt>Message</dt><dd>${exception.message?.encodeAsHTML()}</dd>"
if (root != null && root != exception && root.message != exception.message) { if (root != null && root != exception && root.message != exception.message) {
currentOut << "<strong>Caused by:</strong> ${root.message?.encodeAsHTML()} <br />" currentOut << "<dt>Caused by</dt><dd>${root.message?.encodeAsHTML()}</dd>"
} }
currentOut << "</div>" currentOut << "</dl>"


currentOut << errorsViewStackTracePrinter.prettyPrintCodeSnippet(exception) currentOut << errorsViewStackTracePrinter.prettyPrintCodeSnippet(exception)


def trace = errorsViewStackTracePrinter.prettyPrint(exception.cause ?: exception) def trace = errorsViewStackTracePrinter.prettyPrint(exception.cause ?: exception)
if (StringUtils.hasText(trace.trim())) { if (StringUtils.hasText(trace.trim())) {
currentOut << "<h2>Trace</h2>" currentOut << "<h2>Trace</h2>"
currentOut << '<div class="stack"><pre>' currentOut << '<pre class="stack">'
currentOut << trace.encodeAsHTML() currentOut << trace.encodeAsHTML()
currentOut << '</pre></div>' currentOut << '</pre>'
} }
} }

private String prettyPrintStatus(int statusCode) {
"$statusCode: ${WordUtils.capitalizeFully(HttpStatus.valueOf(statusCode).name().replaceAll('_', ' '))}"
}
} }
59 changes: 9 additions & 50 deletions grails-resources/src/grails/grails-app/views/error.gsp
@@ -1,52 +1,11 @@
<!doctype html>
<html> <html>
<head> <head>

<title>Grails Runtime Exception</title>
<title>Grails Runtime Exception</title> <meta name="layout" content="main">
<meta name="layout" content="main"></meta> <link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css">
<style type="text/css"> </head>
h1, h2 { <body>
margin: 10px; <g:renderException exception="${exception}" />
} </body>
.exceptionMessage {
margin: 10px;
border: 1px solid black;
padding: 5px;
background-color:#E9E9E9;
}
.stack {
margin:10px;
margin-left:25px;
margin-right:25px;
border: 1px solid black;
padding: 5px;
overflow:auto;
height: 150px;
}
.snippet {
background-color:white;
border:1px solid black;
margin:10px;
margin-left:25px;
margin-right:25px;
font-family:courier;
}
.snippet .lineNumber {
background-color:black;
font-weight:white;
color:white;
padding-left:3px;
padding-right:3px;
}
.snippet .errorLine .lineNumber {
background-color:#cc0000;
font-weight:bold;
color:white;
}
</style>
</head>

<body>
<g:renderException exception="${exception}" />
</body>
</html> </html>
100 changes: 100 additions & 0 deletions grails-resources/src/war/css/errors.css
@@ -0,0 +1,100 @@
h1, h2 {
margin: 10px 25px 5px;
}

h2 {
font-size: 1.1em;
}

.filename {
font-style: italic;
}

.exceptionMessage {
margin: 10px;
border: 1px solid #000;
padding: 5px;
background-color: #E9E9E9;
}

.error-details,
.stack,
.snippet {
margin: 0 25px 10px;
}

.stack,
.snippet {
border: 1px solid #ccc;
-mox-box-shadow: 0 0 2px rgba(0,0,0,0.2);
-webkit-box-shadow: 0 0 2px rgba(0,0,0,0.2);
box-shadow: 0 0 2px rgba(0,0,0,0.2);
}

/* error details */
.error-details {
line-height: 1.5;
overflow: hidden;
padding: 0;
}

.error-details dt {
clear: left;
float: left;
font-weight: bold;
margin-right: 5px;
}

.error-details dt:after {
content: ":";
}

.error-details dd {
display: block;
}

/* stack trace */
.stack {
padding: 5px;
overflow: auto;
height: 150px;
}

/* code snippet */
.snippet {
background-color: #fff;
font-family: monospace;
}

.snippet .line {
display: block;
}

.snippet .lineNumber {
background-color: #ddd;
color: #999;
display: inline-block;
margin-right: 5px;
padding: 0 3px;
text-align: right;
width: 3em;
}

.snippet .error {
background-color: #fff3f3;
font-weight: bold;
}

.snippet .error .lineNumber {
background-color: #faa;
color: #333;
font-weight: bold;
}

.snippet .line:first-child .lineNumber {
padding-top: 5px;
}

.snippet .line:last-child .lineNumber {
padding-bottom: 5px;
}
1 change: 1 addition & 0 deletions grails-resources/src/war/css/main.css
Expand Up @@ -108,6 +108,7 @@ img {
color: #000; color: #000;
clear: both; clear: both;
font-size: 0.8em; font-size: 0.8em;
margin-top: 1.5em;
padding: 1em; padding: 1em;
min-height: 1em; min-height: 1em;
} }
Expand Down
Expand Up @@ -72,21 +72,21 @@ class ErrorsViewStackTracePrinter extends DefaultStackTracePrinter{
} catch (e) { } catch (e) {
path = resource.filename path = resource.filename
} }
"""<h2>Around line ${lineNumber} of ${path}</h2> """<h2>Around line ${lineNumber} of <span class="filename">${path}</span></h2>
<div class="snippet"><pre>""" <pre class="snippet">"""
} }


@Override @Override
String formatCodeSnippetEnd(Resource resource, int lineNumber) { String formatCodeSnippetEnd(Resource resource, int lineNumber) {
"</div>" "</pre>"
} }


@Override protected String formatCodeSnippetLine(int currentLineNumber, Object currentLine) { @Override protected String formatCodeSnippetLine(int currentLineNumber, Object currentLine) {
return "<div class=\"line\"><span class=\"lineNumber\">${currentLineNumber}:</span> ${currentLine.encodeAsHTML()}</div>" return "<code class=\"line\"><span class=\"lineNumber\">${currentLineNumber}:</span>${currentLine.encodeAsHTML()}</code>"
} }


@Override protected String formatCodeSnippetErrorLine(int currentLineNumber, Object currentLine) { @Override protected String formatCodeSnippetErrorLine(int currentLineNumber, Object currentLine) {
return "<div class=\"errorLine\"><span class=\"lineNumber\">${currentLineNumber}:</span> ${currentLine.encodeAsHTML()}</div>" return "<code class=\"line error\"><span class=\"lineNumber\">${currentLineNumber}:</span>${currentLine.encodeAsHTML()}</code>"
} }


@Override protected int getLineNumberInfo(Throwable cause, int defaultInfo) { @Override protected int getLineNumberInfo(Throwable cause, int defaultInfo) {
Expand Down

0 comments on commit da90fae

Please sign in to comment.