Improve error handling in COPY