Rather than capture an intermediate variable here, could you instead just do:
```
set -o pipefail
```

To make sure the failure is propagated outside of the pipeline?

I think it's a bit simpler.