if_error,<command>,<error_action> is a useful command, which sets an error action <error_action> for instances of <command> following if_error instance.
<error_action> could be the following:
- continue - ignore any possible error and continue running the script
- ignore - the same as continue
- abort - abort running the script after the command which caused an error
- halt - seems to be the same as abort
I think if_error is very useful sometimes, for example, when one makes a region backup before erasing the region. Saving the backup could fail, but erasing the region won't :)
For example, let's consider the following update.txt script:
When it's run the following update.log is produced:Code:if_error,rrgn,ignore
rrgn,1,1:/01.bin
rrgn,1,1:/02.bin
if_error,rrgn,halt
rrgn,1,1:/03.bin
rrgn,1,1:/04.bin
reboot
Region number 1 doesn't exist, so all instances of rrgn,1, should have caused an error. But because of if_error,rrgn,ignore the first two completed successfully. And then because of if_error,rrgn,halt the third one aborted the script.Code:Parsing "if_error,rrgn,ignore"
Parsing "rrgn,1,1:/01.bin"
Success
Parsing "rrgn,1,1:/02.bin"
Success
Parsing "if_error,rrgn,halt"
Parsing "rrgn,1,1:/03.bin"
Error - update halted
Note that if a script is aborted, last_id.bin is not saved, even if write_last_id,1 is present. Therefore, the script would run many times if used on the same device.