handle write error