Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-38630

function call with wrong parameter count throws wrong error

    XMLWordPrintable

Details

    Description

      Using this script:

      def someFunction(someparam, anotherParam) {
      }
      someFunction("onlyOneParam")
      

      will throw this wrong exception: (instead something about the parameter count would be expected)

      java.lang.NoSuchMethodError: No such DSL method 'someFunction' found among steps [acceptGitLabMR, addGitLabMRComment, archive, artifactoryDownload, artifactoryPromoteBuild, artifactoryUpload, bat, build, catchError, checkout, collectEnv, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, envVarsForTool, error, fileExists, getArtifactoryServer, git, gitlabBuilds, gitlabCommitStatus, input, isUnix, load, mail, marathon, milestone, newArtifactoryServer, newBuildInfo, node, parallel, properties, publishBuildInfo, pwd, readFile, readTrusted, retry, script, sh, sleep, sshagent, stage, stash, step, svn, timeout, timestamps, tool, unarchive, unstash, updateGitlabCommitStatus, waitUntil, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeFile, ws] or symbols [all, always, apiToken, architecture, archiveArtifacts, artifactManager, batchFile, booleanParam, buildButton, buildDiscarder, caseInsensitive, caseSensitive, choice, choiceParam, clock, cloud, command, cron, crumb, defaultView, demand, disableConcurrentBuilds, downloadSettings, downstream, dumb, envVars, file, fileParam, filePath, fingerprint, frameOptions, freeStyle, freeStyleJob, git, hyperlink, hyperlinkToModels, installSource, jdk, jdkInstaller, jgit, jnlp, jobDsl, jobName, junit, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, legacy, list, local, location, logRotator, loggedInUsersCanDoAnything, masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, myView, nodeProperties, nonStoredPasswordParam, none, paneStatus, parameters, password, pattern, pipelineTriggers, plainText, plugin, projectNamingStrategy, proxy, queueItemAuthenticator, quietPeriod, run, runParam, schedule, scm, scmRetryCount, search, security, shell, slave, stackTrace, standard, status, string, stringParam, swapSpace, text, textParam, tmpSpace, toolLocation, unsecured, upstream, viewsTabBar, weather, zfs, zip]
      	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:145)
      	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:117)
      	at groovy.lang.GroovyObject$invokeMethod$1.call(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
      	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115)
      	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:123)
      	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:16)
      	at WorkflowScript.run(WorkflowScript:107)
      	at ___cps.transform___(Native Method)
      	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:48)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
      	at sun.reflect.GeneratedMethodAccessor221.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
      	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
      	at com.cloudbees.groovy.cps.Next.step(Next.java:58)
      	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
      	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:361)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:80)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:236)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:226)
      	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:745)
      

      Attachments

        Activity

          jglick Jesse Glick added a comment -

          If the corresponding mistake in stock Groovy supplies a meaningful error then this probably reflects CpsScript.invokeMethod needing to call super first rather than last, though then any NoSuchMethodError would need to be annotated to mention defined steps as well.

          jglick Jesse Glick added a comment - If the corresponding mistake in stock Groovy supplies a meaningful error then this probably reflects CpsScript.invokeMethod needing to call super first rather than last, though then any NoSuchMethodError would need to be annotated to mention defined steps as well.

          Yes,
          a stock debian groovy 2.4.7 interpreter handles it like that:

          _groovy /tmp/test.groovy
          Caught: groovy.lang.MissingMethodException: No signature of method: test.someFunction() is applicable for argument types: (java.lang.String) values: [onlyOneParam]
          Possible solutions: someFunction(java.lang.Object, java.lang.Object)
          groovy.lang.MissingMethodException: No signature of method: test.someFunction() is applicable for argument types: (java.lang.String) values: [onlyOneParam]
          Possible solutions: someFunction(java.lang.Object, java.lang.Object)
          at test.run(test.groovy:3)_

          which is what one would actually expect.

          dothebart Wilfried Goesgens added a comment - Yes, a stock debian groovy 2.4.7 interpreter handles it like that: _groovy /tmp/test.groovy Caught: groovy.lang.MissingMethodException: No signature of method: test.someFunction() is applicable for argument types: (java.lang.String) values: [onlyOneParam] Possible solutions: someFunction(java.lang.Object, java.lang.Object) groovy.lang.MissingMethodException: No signature of method: test.someFunction() is applicable for argument types: (java.lang.String) values: [onlyOneParam] Possible solutions: someFunction(java.lang.Object, java.lang.Object) at test.run(test.groovy:3)_ which is what one would actually expect.
          elaine_richards_symantec Elaine Richards added a comment - - edited

          I just spent 90 minutes trying to figure out why a new method I added did not show up. I want to be able to have a method where, if no argument is given, the internal logic of the method assigns a default value. 

          Getting a message saying "No such DSL method" is unacceptable.

          Also, I want to be able to write a method where I can call it without feeding it arguments and letting it take care of itself.

          Is anyone going to at least address the misleading error output?

           

          – I'd like to add that I tried enclosing calls to the method inside a try {} catch(err){} syntax and it still barfed the same way. 

          elaine_richards_symantec Elaine Richards added a comment - - edited I just spent 90 minutes trying to figure out why a new method I added did not show up. I want to be able to have a method where, if no argument is given, the internal logic of the method assigns a default value.  Getting a message saying "No such DSL method" is unacceptable. Also, I want to be able to write a method where I can call it without feeding it arguments and letting it take care of itself. Is anyone going to at least address the misleading error output?   – I'd like to add that I tried enclosing calls to the method inside a try {} catch(err){} syntax and it still barfed the same way. 

          you should probably vote for this bug then to start with

          dothebart Wilfried Goesgens added a comment - you should probably vote for this bug then to start with

          People

            Unassigned Unassigned
            dothebart Wilfried Goesgens
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: