[MAGNOLIA-4671] Bad error handling for method for info.magnolia.templating.functions.TemplatingFunctions#link Created: 16/Nov/12 Updated: 07/Jun/18 Resolved: 07/Jun/18 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | templating |
| Affects Version/s: | 4.5.4 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Neutral |
| Reporter: | Per Andersson [X] (Inactive) | Assignee: | Unassigned |
| Resolution: | Obsolete | Votes: | 0 |
| Labels: | errorhandling, freemarker, templating | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Template: |
|
||||||||
| Acceptance criteria: |
Empty
|
||||||||
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
||||||||
| Date of First Response: | |||||||||
| Description |
|
Hi, When calling the method "info.magnolia.templating.functions.TemplatingFunctions#link" from freemarker using: <#assign dmsLink = cmsfn.link("dms", "/demo-docs/children/wizoz10") />
The only error visible for me is: Error on line 95, column 11 in path/to/template
cmsfn.link("dms", "/demo-docs/children/wizoz10") is undefined.
It cannot be assigned to dmsLink
The problematic instruction:
----------
==> assignment: dmsLink=cmsfn.link("dms", "/demo-docs/children/wizoz10") [on line 95, column 11 in path/to/template]
----------
Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Error on line 95, column 11 in path/to/template
cmsfn.link("dms", "/demo-docs/children/wizoz10") is undefined.
It cannot be assigned to dmsLink
at freemarker.core.Assignment.accept(Assignment.java:111)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
When downloading the source code I've found: public String link(String workspace, String nodeIdentifier) {
try {
return LinkUtil.createLink(workspace, nodeIdentifier);
} catch (RepositoryException e) {
return null;
}
}
The real error "javax.jcr.RepositoryException: invalid identifier: /demo-docs/children/wizoz10" was hidden from me because of this. I first assumed that the method "link" was missing due to the error visible to me in the log. Better consistency for the error handling in this file would be appreciated. Example: public String link(String workspace, String nodeIdentifier) {
try {
return LinkUtil.createLink(workspace, nodeIdentifier);
} catch (RepositoryException e) {
log.error(e.getMessage(), e); // Print the real error in the log
return null;
}
}
Also I see other methods have the same problem, those should be updated as well. |
| Comments |
| Comment by Jan Haderka [ 16/Nov/12 ] |
|
Hi Per, the exception is swallowed in this call to allow freemarker templates to check easily whether link can be created or now. But you are absolutely correct that it should not be swallowed silently, but should be logged instead. Thanks, for reporting the problem. Jan |
| Comment by Mikaël Geljić [ 07/Jun/18 ] |
|
Debug logs were added in |