check for error code before fs.exists