Browse files

Merge pull request #2176 from nraychaudhuri/intellij_friendly_error

Intellij friendly error message
  • Loading branch information...
2 parents e575f02 + c5b0cd6 commit f2f77b9dfc92eff4f196e73e8a91eb5775dbf97a @huntc huntc committed Feb 28, 2014
View
43 framework/src/play-integration-test/src/test/scala/play/it/views/DevErrorPageSpec.scala
@@ -0,0 +1,43 @@
+package play.it.views
+
+import play.api.test.PlaySpecification
+
+import play.api.test._
+import play.api.DefaultGlobal
+import java.lang.String
+import scala.Predef.String
+
+object DevErrorPageSpec extends PlaySpecification{
+
+
+ "devError.scala.html" should {
+
+ val testExceptionSource = new play.api.PlayException.ExceptionSource("test","making sure the link shows up") {
+ def line = 100.asInstanceOf[Integer]
+ def position = 20.asInstanceOf[Integer]
+ def input = "test"
+ def sourceName = "someSourceFile"
+ }
+
+ "link the error line if play.editor is configured" in {
+ try {
+ System.setProperty("play.editor", "someEditorLinkWith %s:%s")
+ val result = DefaultGlobal.onError(FakeRequest(), testExceptionSource)
+ Helpers.contentAsString(result) must contain("""href="someEditorLinkWith someSourceFile:100" """)
+ } finally {
+ System.clearProperty("play.editor")
+ }
+ }
+
+ "show prod error page in prod mode" in {
+ val fakeApplication = new FakeApplication() {
+ override val mode = play.api.Mode.Prod
+ }
+ running(fakeApplication) {
+ val result = DefaultGlobal.onError(FakeRequest(), testExceptionSource)
+ Helpers.contentAsString(result) must contain("Oops, an error occured")
+ }
+ }
+ }
+
+}
View
8 framework/src/play/src/main/scala/play/api/GlobalSettings.scala
@@ -138,11 +138,13 @@ trait GlobalSettings {
* @return The result to send to the client
*/
def onError(request: RequestHeader, ex: Throwable): Future[SimpleResult] = {
+ def devError = views.html.defaultpages.devError(Option(System.getProperty("play.editor"))) _
+ def prodError = views.html.defaultpages.error.f
try {
Future.successful(InternalServerError(Play.maybeApplication.map {
- case app if app.mode != Mode.Prod => views.html.defaultpages.devError.f
- case app => views.html.defaultpages.error.f
- }.getOrElse(views.html.defaultpages.devError.f) {
+ case app if app.mode == Mode.Prod => prodError
+ case app => devError
+ }.getOrElse(devError) {
ex match {
case e: UsefulException => e
case NonFatal(e) => UnexpectedException(unexpected = Some(e))
View
22 framework/src/play/src/main/scala/views/defaultpages/devError.scala.html
@@ -2,7 +2,7 @@
* Default page for 500 Internal Server Error responses, in development mode.
* This page display the error in the source code context.
*@
-@(error: play.api.UsefulException)
+@(playEditor: Option[String])(error: play.api.UsefulException)
<!DOCTYPE html>
<html>
@@ -25,7 +25,10 @@
border-bottom: 1px solid #690000;
font-size: 28px;
}
- p#detail {
+ a {
+ color: #D36D6D;
+ }
+ p#detail {
margin: 0;
padding: 15px 45px;
background: #F5A0A0;
@@ -129,13 +132,20 @@
@Option(source.sourceName).map { name =>
<h2>
- In @name @Option(source.line).map { line =>
- at line @line.
- }
+ In @Option(source.line).fold {
+ @name (line number not found)
+ }{line =>
+ @playEditor.fold {
+ @name:@line
+ } { link =>
+ <iframe name="_onlyForFiringEditorLink" style="display:none;"></iframe>
+ <a href="@{link.format(name, line)}" target="_onlyForFiringEditorLink">@name:@line</a>
+ }
+ }
</h2>
<div id="source-code">
- @Option(source.interestingLines(4)).map {
+ @Option(source.interestingLines(4)).map {
case interesting => {

0 comments on commit f2f77b9

Please sign in to comment.