show error message and add safety check