Failing fast

Failing fast#

Aim of this section: Avoid cascading failures and hard–to–debug situations by exiting the script at the first sign of trouble.

See Fail–Fast Settings for an in–depth discussion of why, how and when these settings protect you.

A fail–fast script exits as soon as it encounters an error. You can think of it as pre–flight checks: everything has to line up just so for the script to do its job properly. Continuing in case of an error does not guarantee failure, but

  • there are generally many more ways a command can fail than succeed,

  • the failure modes are usually not tested, and

  • failure modes compound when running more commands with broken state.

So you will be very lucky to get the result you want despite an error, and pretty lucky if all you have to do is tweak something before re–running the command. Permanent data loss (even unrelated to the input data) or ending up in an unknown state are common results.

 

This page is a preview of The newline Guide to Bash Scripting

No discussions yet