[core] Don't run ERR trap in 'errexit disabled' situations, and inside functions