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

Detailed errors with stack trace of the original problem #219

Merged
merged 1 commit into from Jun 30, 2016

Conversation

Projects
None yet
2 participants
@haumacher
Contributor

haumacher commented Jun 25, 2015

If jbake crashes with an exception, no detailed stack traces are reported. If exceptions are thrown e.g. during rendering, these exceptions are caught and their messages are recorded. Afterwards, a fresh exception is thrown with all aggregated messages concatenated - so far so good. The problem is that the new exception has no linked cause making debugging a nightmare. It would be better to not record the messages but the exceptions themselves, build the new exception message from their messages, but at least link the first cause as cause of the new exception.

Besides that, it is good practice to link wrapped exceptions to their cause. Whenever one has the pattern

} catch (AException ex) {
   throw new BException("...");
}

this should be re-written as

} catch (AException ex) {
   throw new BException("...", ex);
}
When wrapping exceptions (catching and throwing new ones), keep the
original exception linked to the newly thrown exception. This provides a
detailed stack trace in the case of an error and makes debugging much
more easy.
@jonbullock

This comment has been minimized.

Show comment
Hide comment
@jonbullock

jonbullock Aug 13, 2015

Member

Sounds like a good improvement... have you got an example you've tested this with so I can see what it looks like in practice?

Member

jonbullock commented Aug 13, 2015

Sounds like a good improvement... have you got an example you've tested this with so I can see what it looks like in practice?

@jonbullock jonbullock self-assigned this Aug 13, 2015

@haumacher

This comment has been minimized.

Show comment
Hide comment
@haumacher

haumacher Aug 17, 2015

Contributor

When something goes wrong during development (e.g. a NullPointerException), you get the following output with the original version:

JBake failed with 35 errors:
1. Failed to render file. Cause: null
...
35. Failed to render tags. Cause(s):
null
null
null
null

org.jbake.app.JBakeException: JBake failed with 35 errors:
1. Failed to render file. Cause: null
...
35. Failed to render tags. Cause(s):
null
null
null
null

    at org.jbake.launcher.Main.bake(Main.java:62)
    at org.jbake.launcher.Main.run(Main.java:86)
    at org.jbake.launcher.Main.main(Main.java:36)

This gives absolutely no clue about the location of the error. With the change included the output looks like the following:

org.jbake.app.JBakeException: JBake failed with 35 errors:
1. Failed to render file. Cause: null
...
35. Failed to render tags. Cause(s):
null
...
null

    at org.jbake.launcher.Main.bake(Main.java:62)
    at org.jbake.launcher.Main.run(Main.java:86)
    at org.jbake.launcher.Main.main(Main.java:36)
Caused by: java.lang.Exception: Failed to render file. Cause: null
    at org.jbake.app.Renderer.render(Renderer.java:96)
    at org.jbake.app.Oven.bakeIncremental(Oven.java:193)
    at org.jbake.app.Oven.bake(Oven.java:164)
    at org.jbake.launcher.Main.bake(Main.java:50)
    ... 2 more
Caused by: java.lang.NullPointerException
    at org.jbake.template.ThymeleafTemplateEngine.renderDocument(ThymeleafTemplateEngine.java:87)
    at org.jbake.template.DelegatingTemplateEngine.renderDocument(DelegatingTemplateEngine.java:65)
    at org.jbake.app.Renderer.renderDocument(Renderer.java:111)
    at org.jbake.app.Renderer.render(Renderer.java:89)
    ... 5 more

Which easily shows, that something is wrong invoking the ThymeleafTemplateEngine.

Contributor

haumacher commented Aug 17, 2015

When something goes wrong during development (e.g. a NullPointerException), you get the following output with the original version:

JBake failed with 35 errors:
1. Failed to render file. Cause: null
...
35. Failed to render tags. Cause(s):
null
null
null
null

org.jbake.app.JBakeException: JBake failed with 35 errors:
1. Failed to render file. Cause: null
...
35. Failed to render tags. Cause(s):
null
null
null
null

    at org.jbake.launcher.Main.bake(Main.java:62)
    at org.jbake.launcher.Main.run(Main.java:86)
    at org.jbake.launcher.Main.main(Main.java:36)

This gives absolutely no clue about the location of the error. With the change included the output looks like the following:

org.jbake.app.JBakeException: JBake failed with 35 errors:
1. Failed to render file. Cause: null
...
35. Failed to render tags. Cause(s):
null
...
null

    at org.jbake.launcher.Main.bake(Main.java:62)
    at org.jbake.launcher.Main.run(Main.java:86)
    at org.jbake.launcher.Main.main(Main.java:36)
Caused by: java.lang.Exception: Failed to render file. Cause: null
    at org.jbake.app.Renderer.render(Renderer.java:96)
    at org.jbake.app.Oven.bakeIncremental(Oven.java:193)
    at org.jbake.app.Oven.bake(Oven.java:164)
    at org.jbake.launcher.Main.bake(Main.java:50)
    ... 2 more
Caused by: java.lang.NullPointerException
    at org.jbake.template.ThymeleafTemplateEngine.renderDocument(ThymeleafTemplateEngine.java:87)
    at org.jbake.template.DelegatingTemplateEngine.renderDocument(DelegatingTemplateEngine.java:65)
    at org.jbake.app.Renderer.renderDocument(Renderer.java:111)
    at org.jbake.app.Renderer.render(Renderer.java:89)
    ... 5 more

Which easily shows, that something is wrong invoking the ThymeleafTemplateEngine.

@jonbullock

This comment has been minimized.

Show comment
Hide comment
@jonbullock

jonbullock Sep 29, 2015

Member

Thanks for taking the time to highlight the benefits. I'll update the PR when I know which release this will be included in.

Member

jonbullock commented Sep 29, 2015

Thanks for taking the time to highlight the benefits. I'll update the PR when I know which release this will be included in.

@jonbullock jonbullock added this to the v2.5.0 milestone Nov 11, 2015

@jonbullock jonbullock merged commit 9e50bd1 into jbake-org:master Jun 30, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

jonbullock added a commit that referenced this pull request Jun 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment