fix error handling in synchronous fs calls