To be honest this whole function should be merged with the other `error_for_oserror` function.