Ticket #41 (new task)
Error handling in template engine
| Reported by: | jgou | Owned by: | jgou |
|---|---|---|---|
| Priority: | minor | Milestone: | 0.5 |
| Component: | universe/kauri-template | Version: | trunk |
| Keywords: | Cc: |
Description
So far little effort has been put in error handling in the kauri template engine.
We should think about a useful strategy such as 'failfast' and do a decent implementation of it.
Attachments
Change History
comment:2 Changed 4 years ago by bruno
I would suggest using the technique of a callback interface for reporting errors, warnings and other messages. This way, the error handling is not hardcoded. This can also remove the need for a dependency on a logging library in the template engine.
There are examples around of this technique, e.g. org.xml.sax.ErrorHandler.
A rather generic design for such an interface could be:
interface ErrorHandler {
void fatalError(String message);
void fatalError(String message, Throwable t);
void warning(String message);
void warning(String message, Throwable t);
void info(String message);
}
Though we could also consider more fine-grained methods for cases where we're not sure what to do. For example, is an error in an expression fatal or not? This could be solved by having methods like
void expressionCompilationError(String expression, Location location, String message, Throwable t);
While at it, here's a (non-exhaustive) list of places I've noticed that need error handling improvements:
- ELFacade
- DefaultTemplateBuilder.buildTemplate
- DefaultTemplateBuilder: reporting of "Unsupported KTL directive"
- TemplateExecutor
Another aspect of this error-handling is decent reporting of location (filename, line and column) of the tags ans expressions leading to the exception.
juel seems to do it's share:
Caused by: javax.el.ELException: Error parsing '${publicUri(km:/sample-data')}': syntax error at position 14, encountered ':', expected ')'
but in this case I'm left to wonder in which file at what position this expression is to be found