What this really boils down to is you should avoid subshells where possible and handle this with either variable assignment or and streams (pipes).
eg:
set -euo pipefail
foo() {
false
echo "hello world"
}
variable=$(foo) # failsfoo | do_stuff # fails
My preference is to handle things as streams