Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2226

Errors in templates syntax produce not so helpful error messages

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1-beta-1
    • 1.5.2
    • None
    • None

    Description

      This code has a problem at least in the last <% %>:

      class A {
         def static engine = new groovy.text.SimpleTemplateEngine()
         def static templt = engine.createTemplate('''
         <html>
         <body>
            <% if(a == 1) %>
               a == 1
            <% else %>
               a != 1
            <% %>
         </body>
         </html>
         ''')
      }
      
      a = new A()
      println a.templt.make([a: 1])
      

      it produces:

      Caught: java.lang.ExceptionInInitializerError
              at t.class$(t.groovy)
              at t.run(t.groovy:16)
              at t.main(t.groovy)
      

      which gives no clue that the problem is in the template body (I suppose I always have to use if-statement with curly brackets).
      It is almost impossible to track this error in a real environment with big template sitting not even in the code but somewhere else.

      If I replace the hole <bod...</body> with <body><%></body> the error is the same.
      If I change template variable declaration to non-static, the error is a bit better but still not good:

      Caught: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
      failed, Script1.groovy: 5: unexpected token: ; @ line 5, column 33.
      1 error
      
              at A.<init>(t.groovy:3)
              at t.run(t.groovy:16)
              at t.main(t.groovy)
      

      Where this Script1.groovy comes from? I have no ';' in my code ...

      Attachments

        Activity

          People

            paulk Paul King
            yegor Yegor Kozlov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: