Skip to content

Commit 8c33bf0

Browse files
committed
fix: improve error handling for loading resolved codes file in exception code generation
1 parent 79ceb0c commit 8c33bf0

File tree

1 file changed

+4
-52
lines changed

1 file changed

+4
-52
lines changed

backends/generators/generator.py

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -512,58 +512,10 @@ def load_exception_codes(
512512
logging.error(
513513
f"Error loading resolved codes file {resolved_codes_file}: {e}"
514514
)
515-
# Fall back to processing YAML files
516-
517-
for dirpath, _, filenames in os.walk(ext_dir):
518-
for fname in filenames:
519-
if not fname.endswith(".yaml"):
520-
continue
521-
522-
found_files += 1
523-
path = os.path.join(dirpath, fname)
524-
525-
try:
526-
with open(path, encoding="utf-8") as f:
527-
data = yaml.safe_load(f)
528-
529-
if not isinstance(data, dict) or data.get("kind") != "extension":
530-
continue
531-
532-
found_extensions += 1
533-
ext_name = data.get("name", "unnamed")
534-
535-
# Skip extension filtering if include_all is True
536-
if not include_all:
537-
# Filter by extension requirements
538-
definedBy = data.get("definedBy")
539-
if definedBy:
540-
meets_req = parse_extension_requirements(definedBy)
541-
if not meets_req(enabled_extensions):
542-
continue
543-
544-
# Check if excluded
545-
excludedBy = data.get("excludedBy")
546-
if excludedBy:
547-
exclusion_check = parse_extension_requirements(excludedBy)
548-
if exclusion_check(enabled_extensions):
549-
continue
550-
551-
# Get exception codes
552-
for code in data.get("exception_codes", []):
553-
num = code.get("num")
554-
name = code.get("name")
555-
556-
if num is not None and name is not None:
557-
sanitized_name = (
558-
name.lower()
559-
.replace(" ", "_")
560-
.replace("/", "_")
561-
.replace("-", "_")
562-
)
563-
exception_codes.append((num, sanitized_name))
564-
565-
except Exception as e:
566-
logging.error(f"Error processing file {path}: {e}")
515+
# Logging an error and skipping the exception cause generation if no resolved codes file found
516+
else:
517+
logging.error(f"Error loading resolved codes file {resolved_codes_file}: {e}")
518+
return
567519

568520
if found_extensions > 0:
569521
logging.info(

0 commit comments

Comments
 (0)