From b7e6e2cee39855c1c0184e88aa1c3759dff5d985 Mon Sep 17 00:00:00 2001 From: Laren Crawford Date: Fri, 2 May 2025 16:11:25 -0700 Subject: [PATCH] Some tributary categories use a different format for their IDs (like IAM policies). Safely split and return unknown if they are not in the standard category format. --- aws_doc_sdk_examples_tools/doc_gen.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aws_doc_sdk_examples_tools/doc_gen.py b/aws_doc_sdk_examples_tools/doc_gen.py index 366c095..ca8f074 100644 --- a/aws_doc_sdk_examples_tools/doc_gen.py +++ b/aws_doc_sdk_examples_tools/doc_gen.py @@ -264,8 +264,15 @@ def validate(self): ) def fill_missing_fields(self): + def safe_split_id(ex_id: str) -> Tuple[str, str]: + if "_" in example.id: + svc, act = ex_id.split("_", 1) + else: + svc, act = "unknown_service", "unknown_action" + return svc, act + for example in self.examples.values(): - id_service, id_action = example.id.split("_", 1) + id_service, id_action = safe_split_id(example.id) service_id = example.service_main or next( (k for (k, _) in example.services.items()), None ) @@ -274,7 +281,7 @@ def fill_missing_fields(self): service_id = id_service action = ( next((k for k in example.services.get(service_id, [])), None) - or example.id.split("_", 1)[1] + or safe_split_id(example.id)[1] ) if action is None: # TODO Log and find which tributaries this effects, as it was supposed to be caught by validations.