propagate errors write

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
Merge pull request #5613 from vieux/better_error_handling

propagate errors write