Make sure err exists before trying to access it