@@ -50,6 +50,27 @@ class WorkflowCatalogEntry:
5050 description : str = ""
5151
5252
53+ def _normalize_catalog_priority (
54+ value : Any ,
55+ * ,
56+ catalog_name : str | int ,
57+ error_cls : type [Exception ],
58+ ) -> int :
59+ """Normalize a catalog priority to int and reject bool explicitly."""
60+ if isinstance (value , bool ):
61+ raise error_cls (
62+ f"Invalid priority for catalog '{ catalog_name } ': "
63+ f"expected integer, got { value !r} "
64+ )
65+ try :
66+ return int (value )
67+ except (TypeError , ValueError ) as exc :
68+ raise error_cls (
69+ f"Invalid priority for catalog '{ catalog_name } ': "
70+ f"expected integer, got { value !r} "
71+ ) from exc
72+
73+
5374# ---------------------------------------------------------------------------
5475# WorkflowRegistry
5576# ---------------------------------------------------------------------------
@@ -210,14 +231,11 @@ def _load_catalog_config(
210231 if not url :
211232 continue
212233 self ._validate_catalog_url (url )
213- try :
214- priority = int (item .get ("priority" , idx + 1 ))
215- except (TypeError , ValueError ):
216- raise WorkflowValidationError (
217- f"Invalid priority for catalog "
218- f"'{ item .get ('name' , idx + 1 )} ': "
219- f"expected integer, got { item .get ('priority' )!r} "
220- )
234+ priority = _normalize_catalog_priority (
235+ item .get ("priority" , idx + 1 ),
236+ catalog_name = item .get ("name" , idx + 1 ),
237+ error_cls = WorkflowValidationError ,
238+ )
221239 raw_install = item .get ("install_allowed" , False )
222240 if isinstance (raw_install , str ):
223241 install_allowed = raw_install .strip ().lower () in (
@@ -516,28 +534,33 @@ def add_catalog(
516534 f"Catalog URL already configured: { url } "
517535 )
518536
519- # Derive priority from the highest existing priority + 1.
520- # Coerce existing priorities to int with a safe fallback so a user-edited
521- # workflow-catalogs.yml with a non-integer priority (e.g. "1") doesn't blow up.
522- def _coerce_priority (value : Any ) -> int :
523- try :
524- return int (value )
525- except (TypeError , ValueError ):
526- return 0
527-
528537 max_priority = max (
529538 (
530- _coerce_priority (cat .get ("priority" , 0 ))
531- for cat in catalogs
539+ _normalize_catalog_priority (
540+ cat ["priority" ],
541+ catalog_name = cat .get ("name" , idx + 1 ),
542+ error_cls = WorkflowValidationError ,
543+ )
544+ for idx , cat in enumerate (catalogs )
532545 if isinstance (cat , dict )
546+ if "priority" in cat
533547 ),
534548 default = 0 ,
535549 )
550+ catalog_name = name or f"catalog-{ len (catalogs ) + 1 } "
536551 catalogs .append (
537552 {
538- "name" : name or f"catalog- { len ( catalogs ) + 1 } " ,
553+ "name" : catalog_name ,
539554 "url" : url ,
540- "priority" : max_priority + 1 if priority is None else priority ,
555+ "priority" : (
556+ max_priority + 1
557+ if priority is None
558+ else _normalize_catalog_priority (
559+ priority ,
560+ catalog_name = catalog_name ,
561+ error_cls = WorkflowValidationError ,
562+ )
563+ ),
541564 "install_allowed" : install_allowed ,
542565 "description" : description ,
543566 }
@@ -832,14 +855,11 @@ def _load_catalog_config(
832855 if not url :
833856 continue
834857 self ._validate_catalog_url (url )
835- try :
836- priority = int (item .get ("priority" , idx + 1 ))
837- except (TypeError , ValueError ):
838- raise StepValidationError (
839- f"Invalid priority for catalog "
840- f"'{ item .get ('name' , idx + 1 )} ': "
841- f"expected integer, got { item .get ('priority' )!r} "
842- )
858+ priority = _normalize_catalog_priority (
859+ item .get ("priority" , idx + 1 ),
860+ catalog_name = item .get ("name" , idx + 1 ),
861+ error_cls = StepValidationError ,
862+ )
843863 raw_install = item .get ("install_allowed" , False )
844864 if isinstance (raw_install , str ):
845865 install_allowed = raw_install .strip ().lower () in (
@@ -1130,27 +1150,33 @@ def add_catalog(
11301150 f"Catalog URL already configured: { url } "
11311151 )
11321152
1133- # Coerce existing priorities to int with a safe fallback so a user-edited
1134- # step-catalogs.yml with a non-integer priority (e.g. "1") doesn't blow up.
1135- def _coerce_priority (value : Any ) -> int :
1136- try :
1137- return int (value )
1138- except (TypeError , ValueError ):
1139- return 0
1140-
11411153 max_priority = max (
11421154 (
1143- _coerce_priority (cat .get ("priority" , 0 ))
1144- for cat in catalogs
1155+ _normalize_catalog_priority (
1156+ cat ["priority" ],
1157+ catalog_name = cat .get ("name" , idx + 1 ),
1158+ error_cls = StepValidationError ,
1159+ )
1160+ for idx , cat in enumerate (catalogs )
11451161 if isinstance (cat , dict )
1162+ if "priority" in cat
11461163 ),
11471164 default = 0 ,
11481165 )
1166+ catalog_name = name or f"catalog-{ len (catalogs ) + 1 } "
11491167 catalogs .append (
11501168 {
1151- "name" : name or f"catalog- { len ( catalogs ) + 1 } " ,
1169+ "name" : catalog_name ,
11521170 "url" : url ,
1153- "priority" : max_priority + 1 if priority is None else priority ,
1171+ "priority" : (
1172+ max_priority + 1
1173+ if priority is None
1174+ else _normalize_catalog_priority (
1175+ priority ,
1176+ catalog_name = catalog_name ,
1177+ error_cls = StepValidationError ,
1178+ )
1179+ ),
11541180 "install_allowed" : install_allowed ,
11551181 "description" : description ,
11561182 }
0 commit comments