Fix error handling during directory merge.
(cherry picked from commit bde64f7c4f8fbc5df83f3cb194069258867fb49e)