Added checking for errors and raising an OSError if we cannot