From 72e89f1e7ee121a291fd3eb32a5ebb14ca4612e0 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Tue, 14 Jan 2025 17:02:16 +0000 Subject: [PATCH 1/2] Display error message when cannot parse Header and Content To let the user knows more about why there's an error. For example, in a case similar to https://github.com/spdx/spdx-3-model/pull/947#issuecomment-2590551853 Signed-off-by: Arthit Suriyawongkul --- spec_parser/mdparsing.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spec_parser/mdparsing.py b/spec_parser/mdparsing.py index 4b41615..cf344bc 100644 --- a/spec_parser/mdparsing.py +++ b/spec_parser/mdparsing.py @@ -39,10 +39,15 @@ def load(self, fpath): for p in parts[2:]: if p.strip(): m = re.fullmatch(self.RE_EXTRACT_HEADER_CONTENT, p) - header = m.group(1) - content = m.group(2).strip() - if content: - self.sections[header] = content + if m is None: + logging.error(f"File {fpath!s} may contain an empty section.") + else: + header = m.group(1) + content = m.group(2).strip() + if content: + self.sections[header] = content + else: + logging.error(f"Content under header '{header}' in File {fpath!s} is empty.") class Section: From 7ee937320af648e9ec60761bfb008bb1a9ef06e8 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Tue, 14 Jan 2025 19:09:26 +0000 Subject: [PATCH 2/2] Add hint about location Signed-off-by: Arthit Suriyawongkul --- spec_parser/mdparsing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec_parser/mdparsing.py b/spec_parser/mdparsing.py index cf344bc..1e79fcc 100644 --- a/spec_parser/mdparsing.py +++ b/spec_parser/mdparsing.py @@ -40,14 +40,14 @@ def load(self, fpath): if p.strip(): m = re.fullmatch(self.RE_EXTRACT_HEADER_CONTENT, p) if m is None: - logging.error(f"File {fpath!s} may contain an empty section.") + logging.error(f"File {fpath!s} may contain an empty section at `{p}'") else: header = m.group(1) content = m.group(2).strip() if content: self.sections[header] = content else: - logging.error(f"Content under header '{header}' in File {fpath!s} is empty.") + logging.error(f"Content under header `{header}' in File {fpath!s} is empty.") class Section: