Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute: display custom error page during dev mode #12907

Merged
merged 1 commit into from
Nov 3, 2020

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Oct 23, 2020

@mkouba
Copy link
Contributor Author

mkouba commented Oct 23, 2020

Screenshot from 2020-10-23 17-27-44

@machi1990
Copy link
Member

Looks like CI is not happy because of some formatting issues:

Caused by: org.apache.maven.plugin.MojoFailureException: File '/home/runner/work/quarkus/quarkus/core/runtime/src/main/java/io/quarkus/runtime/TemplateHtmlBuilder.java' has not been previously formatted.  Please format file and commit before running validation!

@mkouba
Copy link
Contributor Author

mkouba commented Oct 23, 2020

@machi1990 Yeah, as usual in my case ;-)

@gsmet
Copy link
Member

gsmet commented Oct 23, 2020

That is very ... well ... cute and it's gonna be very useful.

I would maybe add a little more spacing between the details of the error and the code. And also between the end of the code and the second title.

@mkouba
Copy link
Contributor Author

mkouba commented Oct 26, 2020

ErrorPageGenerators is located in the devmode SPI because some extensions don't depend on vertx-http but still may need to produce a custom error page.

@stuartwdouglas QuteErrorPageSetup contains the reflection hacks to avoid the class loading problems I was talking about.

@gsmet
Copy link
Member

gsmet commented Oct 27, 2020

@mkouba is this ready to be merged? Wasn't sure because of your last comment.

@mkouba
Copy link
Contributor Author

mkouba commented Oct 27, 2020

It should be if there are no objections to the implementation...

@FroMage
Copy link
Member

FroMage commented Oct 28, 2020

I will review this today if you let me.

Copy link
Member

@FroMage FroMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Martin, this is great. It looks amazing and is super useful, I love it. Thanks so much.

I've added minor comments, but I can't wait for this to be merged!

@@ -76,6 +76,16 @@ public static String rootCauseFirstStackTrace(final Throwable exception) {
return generateStackTrace(modifiedRoot).replace("Caused by:", "Resulted in:");
}

public static Throwable getRootCause(Throwable exception) {
final List<Throwable> exceptionChain = new ArrayList<>();
Throwable curr = exception;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like the list is not useful, and it feels weird that if the exception has no cause it's not considered the root cause, since null will be returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should only return null if the exception is null, otherwise the list if never empty... However, we should handle the recursive cause structures as well. I'll fix it and add a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* In order to avoid classloading issues the generators should not access the root cause directly but use reflection instead
* (the exception class could be loaded by a different class loader).
*/
public class ErrorPageGenerators {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obviously useful, but I wonder if we should not put something more declarative in place, like ExceptionMapper<T> which JAX-RS has?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this could cause class loading issues...

private static final String TEMPLATE_EXCEPTION = "io.quarkus.qute.TemplateException";
private static final String ORIGIN = "io.quarkus.qute.TemplateNode$Origin";

private static final String PROBLEM_TEMPLATE = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this in a template file? I strongly hate that in Quarkus core we have HTML in Java strings, but I understand why, no matter how mind-numbing frustrating this is. But in Qute this feels wrong, when this can be in a standalone Qute template file. Or is there a reason I'm not seeing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure where to put the template contents. We could extract it later...

}

String generatePage(Throwable exception) {
Escaper escaper = Escaper.builder().add('"', "&quot;").add('\'', "&#39;")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this look like generally useful for pretty much anything HTML? Shouldn't we have something like Escaper.htmlBuilder() or Escaper.builder().forHtml()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an optimized version of a result mapper in the runtime module: https://github.com/quarkusio/quarkus/blob/master/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/HtmlEscaper.java

Maybe we could replace the generic escaper with this one. I'll try to prepare a follow-up PR...

problems = Arrays.asList(suppressed);
}

String problemsFound = "Found " + problems.size() + " Qute problems";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please sort the errors by increasing location? You example screenshot shows the last error shown first and it's confusing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@FroMage FroMage merged commit f0c412a into quarkusio:master Nov 3, 2020
@FroMage FroMage added this to the 1.10 - master milestone Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Qute: nice error page
5 participants