docs: python: abi_regex: catch the right exception for a bad regex

While validating recent CXL ABI documentation updates with
get_abi.py, the 'undefined' mode was found to abort instead of
reporting undocumented ABI entries.

Older Python releases raise re.error, while newer releases expose
re.PatternError. Catching the compatible re.error exception handles
both cases.

Use re.error so the scan continues and reports the remaining
results.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <9f6fa7a9aa6ba9a26b484b911976713356b3fd44.1786139549.git.alison.schofield@intel.com>
This commit is contained in:
Alison Schofield
2026-08-07 15:10:03 -07:00
committed by Jonathan Corbet
parent 22a42ee5da
commit 02299dcd20

View File

@@ -155,7 +155,7 @@ class AbiRegex(AbiParser):
if self.search_string:
if what.find(self.search_string) >= 0:
print(f"What: {what}")
except re.PatternError:
except re.error:
self.log.warning("Ignoring '%s' as it produced an invalid regex:\n"
" '%s'", what, new)
@@ -194,7 +194,7 @@ class AbiRegex(AbiParser):
try:
self.re_string = re.compile(self.search_string)
except re.PatternError as e:
except re.error as e:
msg = f"{self.search_string} is not a valid regular expression"
raise ValueError(msg) from e
@@ -223,9 +223,9 @@ class AbiRegex(AbiParser):
for r, s in self.re_whats:
try:
new = r.sub(s, new)
except re.PatternError as e:
except re.error as e:
# Help debugging troubles with new regexes
raise re.PatternError(f"{e}\nwhile re.sub('{r.pattern}', {s}, str)") from e
raise re.error(f"{e}\nwhile re.sub('{r.pattern}', {s}, str)") from e
v["regex"].append(new)