groovy
  1. groovy
  2. GROOVY-5377

CLONE - Incomprehensible Error Message Passing Partial Evaluated Lambda Function (improved error message for normal closure not on classpath case)

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-beta-3, 1.8.7
    • Component/s: SQL processing
    • Labels:
      None
    • Number of attachments :
      0

      Description

      When executing the code:

      #! /usr/bin/env groovy
      
      import groovy.sql.DataSet
      import groovy.sql.Sql
      
      @Grab ( 'org.xerial:sqlite-jdbc:3.7.2' )
      @GrabConfig ( systemClassLoader = true )
      def database
      final words = [ ]
      try {
        database = Sql.newInstance ( 'jdbc:sqlite:database.db' , 'org.sqlite.JDBC' )
        final wordsTable = new DataSet ( database , 'words' )
        ( 0 ..< 4 ).each { i ->
          words << wordsTable.findAll ( { j , item -> item.id == j }.curry ( i ) ).firstRow ( ).word
        }
      }
      finally {
        database?.close ( )
      }
      println words.join ( '' )
      

      the result is the error:

      Caught: groovy.lang.GroovyRuntimeException: Could not find the ClassNode for MetaClass: groovy.lang.MetaClassImpl@6c1826dc[class org.codehaus.groovy.runtime.CurriedClosure]
      groovy.lang.GroovyRuntimeException: Could not find the ClassNode for MetaClass: groovy.lang.MetaClassImpl@6c1826dc[class org.codehaus.groovy.runtime.CurriedClosure]

      which doesn't really tell the programmer anything useful about the executed code they wrote.

        Issue Links

          Activity

          Hide
          Paul King added a comment -

          So, I was going to propose the current error message changes as per the example below. Assume you have some closure where the source is not available:

          def closure = new GroovyShell().evaluate("def c = { p -> p.lastname == 'Smith' }; c")
          println people.findAll(closure).sql
          

          which currently reports the following error:

          Could not find the ClassNode for MetaClass: org.codehaus.groovy.runtime.metaclass.ClosureMetaClass@1fe571f[class Script1$_run_closure1]
          

          I propose it would become:

          DataSet unable to evaluate expression. AST not available for closure: Script1$_run_closure1. Is the source code on the classpath?
          
          Show
          Paul King added a comment - So, I was going to propose the current error message changes as per the example below. Assume you have some closure where the source is not available: def closure = new GroovyShell().evaluate( "def c = { p -> p.lastname == 'Smith' }; c" ) println people.findAll(closure).sql which currently reports the following error: Could not find the ClassNode for MetaClass: org.codehaus.groovy.runtime.metaclass.ClosureMetaClass@1fe571f[class Script1$_run_closure1] I propose it would become: DataSet unable to evaluate expression. AST not available for closure: Script1$_run_closure1. Is the source code on the classpath?
          Hide
          blackdrag blackdrag added a comment -

          +1

          Show
          blackdrag blackdrag added a comment - +1
          Hide
          Russel Winder added a comment -

          As an error message it certainly works better.

          Is there any way of avoiding this situation being a thing Groovy cannot cope with?

          Show
          Russel Winder added a comment - As an error message it certainly works better. Is there any way of avoiding this situation being a thing Groovy cannot cope with?
          Hide
          Paul King added a comment -

          We have tried various ways of storing away the AST and the simple ways run into problems like 64K String limitations and such. I am sure it can be done and it is something we'd like to do but it hasn't yielded to simple solutions so far. (I thought there was an existing Jira issue but couldn't find it just now with a very quick search.)

          Show
          Paul King added a comment - We have tried various ways of storing away the AST and the simple ways run into problems like 64K String limitations and such. I am sure it can be done and it is something we'd like to do but it hasn't yielded to simple solutions so far. (I thought there was an existing Jira issue but couldn't find it just now with a very quick search.)
          Hide
          Paul King added a comment -

          error message added

          Show
          Paul King added a comment - error message added
          Hide
          Russel Winder added a comment -

          Seems to works as anticipated.

          Show
          Russel Winder added a comment - Seems to works as anticipated.
          Hide
          Paul King added a comment -

          added "Component" to improve future searching ease

          Show
          Paul King added a comment - added "Component" to improve future searching ease

            People

            • Assignee:
              Paul King
              Reporter:
              Russel Winder
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: