I'm reading in a YAML file. If there's a syntax mistake that causes an exception, I send the exception to a logger. What is a way to identify in my logging message which line of the YAML file contains the syntax error?
try:
with open(input_path, "r") as yaml_file:
yaml_dict = yaml.load(yaml_file)
except FileNotFoundError:
logger.error("YAML file {} does not exist".format(input_path), exc_info=True)
sys.exit(1)
except:
logger.critical("Error in reading or parsing YAML file {}".format(input_path), exc_info=True)
sys.exit(1)