Presence of prefetch command causes syntax error when trying to use parameter command

Here is a code snippet that fails evaluation with a syntax error ‘Failed: parameter “error” = “{exit code of action}”’:

prefetch <blah>
extract <blah>
delete __createfile
createfile until _end_
<Solaris bash blah>
_end_
delete shell_blah
move __createfile  shell_blah
wait ./shell_blah > shell_blah.out 2> shell_blah.err
parameter "error" = "{exit code of action}"
if {parameter "error" != "0"}
	exit {parameter "error"}
endif

If the prefetch and extract commands are removed, the evaluation succeeds and the script is executed.

If the parameter “error” statement is removed and the if block removed, the evaluation succeeds, the prefetch and extract run, and the script is executed. Of course, without the parameter command and the if block that references it, I can’t use the exit status of the script to indicate the fixlet has failed.

This is expected as when the prefetch is present there is a “download” phase where the action has to evaluate the actionscript for the needed downloads. Setting a parameter like this requires an action to be actually running so it isn’t always possible.

It would probably be better to do a single “continue if” for this error condition like is done in the server upgrade fixlet for example

continue if {exists true whose (if true then (exit code of action = 0) else false)}

The condition around the “exit code of action” protects it from the case where there is no action running.

1 Like

Thank you very much, this appears to do exactly what I want, though I do not really understand why.

How exactly does the statement “continue if {exists true whose (if true then (exit code of action = 0) else false)}” evaluate the return code from the script?

The actionscript command “continue if” will only continue if the following is True.

The expression is a way of catching errors and actually giving a True/False answer instead of an error or undefined command etc. It looks unusual and it is but the combination of the whose and the if/then will absorb errors.

(I reformatted you post to put the code in a code tag. When posting Relevance/Script, be sure to highlight the code block and click the “Preformatted Text” icon in the editor bar- it looks like “</>”)

@AlanM’s solution is correct, but I prefer to use a “prefetch block” when possible to get around this condition. You’ll see this problem repeated where you create a file in the action, then try to reference the file in relevance (you’ll get an error during the prefetch processing because the file doesn’t exist). And because the error occurs in prefetch processing, it’s sometimes not logged well; in fact if it’s part of a baseline, the console may show an error on the wrong baseline component!

By moving the prefetch statements into a prefetch block, only the prefetch block is processed before the action starts running, so you don’t have to error-catch on every line of relevance

begin prefetch block
  add prefetch item name=foobar size=123 sha1=1234567asdfasd823 url=http://myserver.com/file1.exe sha256=12348123asdsad
  collect prefetch items
end prefetch block
extract <blah>
delete __createfile
createfile until _end_
<Solaris bash blah>
_end_
delete shell_blah
move __createfile  shell_blah
wait ./shell_blah > shell_blah.out 2> shell_blah.err
continue if {exit code of action = 0}