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

Message from TemplateNotFoundException is "lost" #397

Open
nilshartmann opened this issue Oct 19, 2024 · 3 comments
Open

Message from TemplateNotFoundException is "lost" #397

nilshartmann opened this issue Oct 19, 2024 · 3 comments

Comments

@nilshartmann
Copy link

When the TemplateEngine tries to load a template that cannot be found, the origin TemplateNotFoundException is not logged anywhere. That's a little sad, because the message contains the actual path, the engine tried to load the template from, and that information is very helpful when trying to investigate, why the template could not be loaded.

In gg.jte.TemplateEngine#resolveTemplateOnDemand it is caught, then re-thrown and in finally caught in gg.jte.TemplateEngine#hasTemplate, where the caugt exception is interpreted as false (template does not exists).

 public boolean hasTemplate(String name) {
        try {
            resolveTemplate(name);
            return true;
        } catch (TemplateNotFoundException e) {

           // helpful information in e.getMessage(), but unfortunately lost here :-/
            return false;
        }
    }

I wonder, if somewhere in between this very helpful message could be logged to simplify bug fixing.

@casid casid assigned casid and unassigned casid Oct 20, 2024
@casid
Copy link
Owner

casid commented Oct 20, 2024

Hi @nilshartmann, thank you for reporting!

When using jte directly, this should already be the case, since the render() method should throw this exception when rendering a template that cannot be found.

I assume you are using the spring boot plugin? The hasTemplate method is used in gg.jte.springframework.boot.autoconfigure.JteView#checkResource.

Check whether the underlying resource that the configured URL points to actually exists.
Params:
locale – the desired Locale that we're looking for
Returns:
true if the resource exists (or is assumed to exist); false if we know that it does not exist
Throws:
Exception – if the resource exists but is invalid (e. g. could not be parsed)

Reading the contract, this method seems to behave as expected (does not throw if resource does not exist).

We could add something like this to jte:

public void checkTemplateExists(String name) throws TemplateNotFoundException {
    resolveTemplate(name);
}

And then catch and log the exception in gg.jte.springframework.boot.autoconfigure.JteView#checkResource.

@atomfrede, @tschuehly do you know if there is a way to log messages in the spring boot plugin?

@nilshartmann
Copy link
Author

@casid Yes, you're right, I'm using the Spring Boot starter (for some reason I removed this info from my description 🤦‍♂️)

I think the method behaves correctly but it would be nice to somehow see the original error message.

@atomfrede
Copy link
Contributor

Good point. Let me check how others starters behave, but totally agree at least see the message would be helpful, on particular for typos

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

No branches or pull requests

3 participants