-
Bug
-
Resolution: Fixed
-
Minor
PowerAssertions are a really useful feature of the groovy programming language, as they give you the full information on what is not as it is expected in the error message - the full assert statement with all information about the values.
However, when running CPS transformed, the output is less useful, as it only states what the assertion was that failed, without the values.
Take for example the following pipeline script:
node { def a = 4 stage('without cps') { nonCps(a) } stage('with cps') { def b = [1, 2, 3] try { assert a == b[0] } catch (Throwable e) { echo e.class.toString() echo e.message echo e.stackTrace.join('\n') } } } @NonCPS def nonCps(a) { def b = [1, 2, 3] try { assert a == b[0] } catch (Throwable e) { echo e.class.toString() echo e.message echo e.stackTrace.join('\n') } }
Although the code is the same for NonCPS and with CPS,
NonCPS prints the following:
assert a == b[0] | | | 1 false
(I.e. the value of the whole expression and the value of b[0],
while the CPS transformed version prints no information whatsoever:
assert a == b[0]
N.B.: running the same code in a groovysh actually gives even more information:
assert a == b[0] | | || 4 | |1 | [1, 2, 3] false
That one can be worked around by liberally throwing parentheses at the problem, but that again only works in the NonCPS case:
assert (a == (b[0])) || || |4 |[1, 2, 3] false 1
This makes the assert statement almost useless for writing test jobs for your global library methods, so it would be a really nice addition if the information could be preserved and be added to the message of the PowerAssertionError.
- is related to
-
JENKINS-47736 JEP-200: Switch Remoting/XStream blacklist to a whitelist
- Resolved
- relates to
-
JENKINS-49025 SecurityException: Rejected: java.lang.String$CaseInsensitiveComparator
- Resolved
- links to