Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-4671

Bad error handling for method for info.magnolia.templating.functions.TemplatingFunctions#link

XMLWordPrintable

      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.

        Acceptance criteria

              Unassigned Unassigned
              pean56 Per Andersson [X] (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Task DoD