Use the 'pipefail' option everywhere -- this makes error-handling in command pipelines behave sanely, by returning the first non-zero status in the pipeline (or zero if there wasn't one).