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

No line number when using a non existing step method

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None

      See https://ci.jenkins.io/job/Plugins/job/analysis-model/job/master/32/console

      I had a typo in my script. I would expect that the parser is somewhat smart and shows me at least the line number of the error. Currently I get a multi-line exception, which is not very user friendly.

          [JENKINS-48418] No line number when using a non existing step method

          Andrew Bayer added a comment -

          The line number is there - look for at WorkflowScript.run(WorkflowScript:21) - it's just a pain to find. Yeah, a better message would be good.

          Andrew Bayer added a comment - The line number is there - look for at WorkflowScript.run(WorkflowScript:21) - it's just a pain to find. Yeah, a better message would be good.

          Andrew Bayer added a comment -

          Note to myself or whoever tackles this: the challenge is pretty much entirely in finding the line number. Adding it to the message will be trivial, but first we have to dig it up. The only thing I can think of off the top of my head is to dive through the Thread.currentThread().getStackTrace() until you find an element with the file name WorkflowScript. That, however, wouldn't work for such errors in shared libraries (we wouldn't actually be hosed if we renamed WorkflowScript to something else, well, not so long as we updated it here at the same time as in CpsFlowExecution)...perhaps we could figure out the specific stacks that could come after the CPS transformed line (i.e., in the linked case, at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17), though we'd have something else for non-sandboxed runs) but ehhhh. Yeah.

          Shame we can't report this at compile time, but we can't easily tell at that point whether foo() is actually a method defined in the Jenkinsfile, a shared library foo.groovy, or some other dynamic magic. I'll see if I can think of all the possible things it could be - if we can be 100% sure we've got all the possible legit cases for foo(), we could then theoretically throw a compile error if none of them were satisfied.

          Andrew Bayer added a comment - Note to myself or whoever tackles this: the challenge is pretty much entirely in finding the line number. Adding it to the message will be trivial, but first we have to dig it up. The only thing I can think of off the top of my head is to dive through the Thread.currentThread().getStackTrace() until you find an element with the file name WorkflowScript . That, however, wouldn't work for such errors in shared libraries (we wouldn't actually be hosed if we renamed WorkflowScript to something else, well, not so long as we updated it here at the same time as in CpsFlowExecution )...perhaps we could figure out the specific stacks that could come after the CPS transformed line (i.e., in the linked case, at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17) , though we'd have something else for non-sandboxed runs) but ehhhh. Yeah. Shame we can't report this at compile time, but we can't easily tell at that point whether foo() is actually a method defined in the Jenkinsfile, a shared library foo.groovy , or some other dynamic magic. I'll see if I can think of all the possible things it could be - if we can be 100% sure we've got all the possible legit cases for foo() , we could then theoretically throw a compile error if none of them were satisfied.

            Unassigned Unassigned
            drulli Ulli Hafner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: