Better error handling for read()