Fix: write failures returned an incorrect error