fix error handling of file opens