Powershell action not failing when the script code is specified in it

Powershell action doesn’t fail when the script code is specified in the action itself. It even appends the “Successfully Executed Powershell Script” text at the end of the log. I used the default action options.

That’s because powershell doesn’t actually report the exit code.

I did try this

try {
//user script
}
catch
{
$Error[0]; exit 1
}

and that seems to work well. I’m not sure if this a good idea to include by default or not, but this build has that change. We reserve the right to remove this change if it causes any backwards compatibility issues

https://downloads.finalbuilder.com/downloads/finalbuilder/800/FB800_3056.exe

Thanks Vincent. Then I will use the try/catch approach to prevent future issues in case you undo the change.

After trying with the Try/Catch approach I found that though the action fails when it’s due, this method will only raise the last output line as the error and will miss the actual error in the executed script.
image

I found a method to get the full output in the error. I would like to share it in case anyone find it useful:

1- Use the try/catch approach suggested by Vincent.

2- ‘Ignore Failure’ in the action and log the output to a variable
image

3- Find the string “Script Failed” in the output variable and put the match count into a new variable (this could be improved by regex search of a non-zero exit code)

4- Count the matches and in case its greater than 0, raise an exception with the output content.
image

Get a more detailed error message

1 Like