fix script exit-on-error modes to propagate the right return code