55import yaml
66import os
77import sys
8- from pathlib import Path
98import copy
9+ import traceback
10+ from pathlib import Path
1011
11- # Resolve repository root from this script location: .gitlab/scripts -> esp32 root
12+ # Resolve repository root from this script location
1213SCRIPT_DIR = Path (__file__ ).resolve ().parent
1314REPO_ROOT = SCRIPT_DIR .parent .parent
15+ TESTS_ROOT = REPO_ROOT / "tests"
1416
1517# Ensure we run from repo root so relative paths work consistently
1618try :
1719 os .chdir (REPO_ROOT )
18- except Exception :
19- pass
20-
21- TESTS_ROOT = REPO_ROOT / "tests"
20+ except Exception as e :
21+ sys .stderr .write (f"[WARN] Failed to chdir to repo root '{ REPO_ROOT } ': { e } \n " )
22+ sys .stderr .write (traceback .format_exc () + "\n " )
2223
2324
2425class PrettyDumper (yaml .SafeDumper ):
@@ -35,7 +36,9 @@ def read_json(p: Path):
3536 try :
3637 with p .open ("r" , encoding = "utf-8" ) as f :
3738 return json .load (f )
38- except Exception :
39+ except Exception as e :
40+ sys .stderr .write (f"[WARN] Failed to parse JSON file '{ p } ': { e } \n " )
41+ sys .stderr .write (traceback .format_exc () + "\n " )
3942 return {}
4043
4144
@@ -155,7 +158,9 @@ def sdk_meets_requirements(sdkconfig: Path, ci_json: dict) -> bool:
155158 if not ok :
156159 return False
157160 return True
158- except Exception :
161+ except Exception as e :
162+ sys .stderr .write (f"[WARN] Failed to evaluate requirements against '{ sdkconfig } ': { e } \n " )
163+ sys .stderr .write (traceback .format_exc () + "\n " )
159164 return False
160165
161166
@@ -166,13 +171,13 @@ def parse_list_arg(s: str) -> list[str]:
166171 if txt .startswith ("[" ) and txt .endswith ("]" ):
167172 try :
168173 return [str (x ).strip () for x in json .loads (txt )]
169- except Exception :
170- # Attempt single-quote JSON -> replace with double quotes
174+ except Exception as e :
175+ sys . stderr . write ( f"[WARN] Failed to parse JSON list ' { txt } ': { e } . Retrying with quote normalization. \n " )
171176 try :
172177 fixed = txt .replace ("'" , '"' )
173178 return [str (x ).strip () for x in json .loads (fixed )]
174- except Exception :
175- pass
179+ except Exception as e2 :
180+ sys . stderr . write ( f"[WARN] Failed to parse JSON list after normalization: { e2 } . Falling back to CSV parsing. \n " )
176181 # Fallback: comma-separated
177182 return [part .strip () for part in txt .split ("," ) if part .strip ()]
178183
0 commit comments