check err before logging