Error Variable Randomly Exists After Running CFExecute In Lucee CFML 5.3.3.62
Yesterday, I was running into a bit of confusion when running the cfexecute
tag in Lucee CFML 5.3.3.62. When you define your cfexecute
attributes, you have the opportunity to provide both a variable
attribute and an errorVariable
attribute that hold the success results and the error results, respectively. When using this tag, I had assumed that the errorVariable
would only be defined if an error occurred. However, it seems that the errorVariable
is randomly populated with an empty string even if no error occurs during the cfexecute
execution.
Demonstrating this is quite easy. All we have to do is run the ls
command a few times in a row and check to see which variables exists after it is executed:
<cfscript>
for ( i = 1 ; i <= 20 ; i++ ) {
testExecute();
}
// ------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------- //
public void function testExecute() {
cfexecute(
name = "ls",
arguments = "-al",
variable = "local.results",
errorVariable = "local.error",
timeout = 5
);
if ( local.keyExists( "results" ) ) {
echo( "Success .... " );
}
( local.keyExists( "error" ) )
? echo( "Error exists: true — len: #error.len()# <br />" )
: echo( "Error exists: false <br />" )
;
}
</cfscript>
As you can see, all this does is run the cfexecute
with both the variable
and the errorVariable
attribute defined. We then check to see if the errorVariable
exists. And, when we run this ColdFusion code, we get the following output:
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: false
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
As you can see, in a little over half of the cfexecute
tests, the errorVariable
exists and is populated with an empty string even through the overall execution was a success.
Because of this seemingly random behavior, when using the cfexecute
tag, it appears that you have to both check if the errorVariable
exists and, if it does, whether or not it has any content. At least in Lucee CFML 5.2.9.40 and Lucee CFML 5.3.3.62 (the two different versions that I tested this on).
Want to use code from this post? Check out the license.
Reader Comments
interesting (and annoying!)
looking at the source, it seems to be storing that value in the pageContext for some reason? it then gets pulled out and then reset to "" in setErrorvariable
https://github.com/lucee/Lucee/blob/5.3/core/src/main/java/lucee/runtime/tag/Execute.java#L161
pageContext is sorta like the internal document object for the request
https://github.com/lucee/Lucee/blob/5.3/core/src/main/java/lucee/runtime/tag/_Execute.java#L79
@Zac,
Hmmm, interesting. I am not sure that I am good enough at reading Java to understand what I'm seeing there. But, even if it were to set the value in the page-context, it still seems odd that the outcome would be random :D
Later, I'll test this in Adobe ColdFusion to see if it behaved any differently.
bug filed https://luceeserver.atlassian.net/browse/LDEV-2624
@Zac,
You the man!!