File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ def parse_headers_env_json(raw_headers: Optional[str]) -> Optional[Dict[str, str
112112 return None
113113 try :
114114 parsed_headers = json .loads (raw_headers )
115- except json .JSONDecodeError as exc :
115+ except ( json .JSONDecodeError , ValueError , RecursionError , TypeError ) as exc :
116116 raise HyperbrowserError (
117117 "HYPERBROWSER_HEADERS must be valid JSON object"
118118 ) from exc
Original file line number Diff line number Diff line change @@ -101,6 +101,20 @@ def test_parse_headers_env_json_rejects_invalid_json():
101101 parse_headers_env_json ("{invalid" )
102102
103103
104+ def test_parse_headers_env_json_wraps_recursive_json_errors (
105+ monkeypatch : pytest .MonkeyPatch ,
106+ ):
107+ def _raise_recursion_error (_raw_headers : str ):
108+ raise RecursionError ("nested too deeply" )
109+
110+ monkeypatch .setattr ("hyperbrowser.header_utils.json.loads" , _raise_recursion_error )
111+
112+ with pytest .raises (
113+ HyperbrowserError , match = "HYPERBROWSER_HEADERS must be valid JSON object"
114+ ):
115+ parse_headers_env_json ('{"X-Trace-Id":"abc123"}' )
116+
117+
104118def test_parse_headers_env_json_rejects_non_mapping_payload ():
105119 with pytest .raises (
106120 HyperbrowserError ,
You can’t perform that action at this time.
0 commit comments