handle errors for read()