Fix compilation due to io_error removal

Errors are not handled correctly yet, but it compiles.
Better error handling

Remember the first I/O error we encounter and return it from the main
run loop.