From f799e9a12aa5ac7aa7dfc365f3cd8f9f3a6d587f Mon Sep 17 00:00:00 2001 From: Klaus Thoden Date: Thu, 20 Dec 2018 12:01:30 +0100 Subject: [PATCH] Exception --- idassigner.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/idassigner.py b/idassigner.py index 77400c2..8d7f4ca 100644 --- a/idassigner.py +++ b/idassigner.py @@ -11,6 +11,7 @@ import argparse import logging +import sys from datetime import datetime from lxml import etree from copy import deepcopy @@ -24,7 +25,11 @@ def assign_ids(chapter_tree): """Assign xml:ids to various elements""" - chapter_id = (chapter_tree.attrib["{http://www.w3.org/XML/1998/namespace}id"]) + try: + chapter_id = (chapter_tree.attrib["{http://www.w3.org/XML/1998/namespace}id"]) + except KeyError: + logging.error("Chapter has no id. Exiting") + sys.exit() logging.debug("The id of this chapter is %s", chapter_id) footnotes = chapter_tree.xpath("//t:note[@place='bottom']", namespaces=NS_MAP)