@@ -105,6 +105,52 @@ class _Params(UpdateSessionProfileParams):
105105 manager .update_profile_params ("session-1" , _Params (persist_changes = True ))
106106
107107
108+ def test_sync_update_profile_params_wraps_serialization_errors (
109+ monkeypatch : pytest .MonkeyPatch ,
110+ ):
111+ manager = SyncSessionManager (_SyncClient ())
112+ params = UpdateSessionProfileParams (persist_changes = True )
113+
114+ def _raise_model_dump_error (* args , ** kwargs ):
115+ _ = args
116+ _ = kwargs
117+ raise RuntimeError ("broken model_dump" )
118+
119+ monkeypatch .setattr (
120+ UpdateSessionProfileParams , "model_dump" , _raise_model_dump_error
121+ )
122+
123+ with pytest .raises (
124+ HyperbrowserError , match = "Failed to serialize update_profile_params payload"
125+ ) as exc_info :
126+ manager .update_profile_params ("session-1" , params )
127+
128+ assert isinstance (exc_info .value .original_error , RuntimeError )
129+
130+
131+ def test_sync_update_profile_params_preserves_hyperbrowser_serialization_errors (
132+ monkeypatch : pytest .MonkeyPatch ,
133+ ):
134+ manager = SyncSessionManager (_SyncClient ())
135+ params = UpdateSessionProfileParams (persist_changes = True )
136+
137+ def _raise_model_dump_error (* args , ** kwargs ):
138+ _ = args
139+ _ = kwargs
140+ raise HyperbrowserError ("custom model_dump failure" )
141+
142+ monkeypatch .setattr (
143+ UpdateSessionProfileParams , "model_dump" , _raise_model_dump_error
144+ )
145+
146+ with pytest .raises (
147+ HyperbrowserError , match = "custom model_dump failure"
148+ ) as exc_info :
149+ manager .update_profile_params ("session-1" , params )
150+
151+ assert exc_info .value .original_error is None
152+
153+
108154def test_async_update_profile_params_bool_warns_and_serializes ():
109155 AsyncSessionManager ._has_warned_update_profile_params_boolean_deprecated = False
110156 client = _AsyncClient ()
@@ -164,6 +210,56 @@ async def run() -> None:
164210 asyncio .run (run ())
165211
166212
213+ def test_async_update_profile_params_wraps_serialization_errors (
214+ monkeypatch : pytest .MonkeyPatch ,
215+ ):
216+ manager = AsyncSessionManager (_AsyncClient ())
217+ params = UpdateSessionProfileParams (persist_changes = True )
218+
219+ def _raise_model_dump_error (* args , ** kwargs ):
220+ _ = args
221+ _ = kwargs
222+ raise RuntimeError ("broken model_dump" )
223+
224+ monkeypatch .setattr (
225+ UpdateSessionProfileParams , "model_dump" , _raise_model_dump_error
226+ )
227+
228+ async def run () -> None :
229+ with pytest .raises (
230+ HyperbrowserError , match = "Failed to serialize update_profile_params payload"
231+ ) as exc_info :
232+ await manager .update_profile_params ("session-1" , params )
233+ assert isinstance (exc_info .value .original_error , RuntimeError )
234+
235+ asyncio .run (run ())
236+
237+
238+ def test_async_update_profile_params_preserves_hyperbrowser_serialization_errors (
239+ monkeypatch : pytest .MonkeyPatch ,
240+ ):
241+ manager = AsyncSessionManager (_AsyncClient ())
242+ params = UpdateSessionProfileParams (persist_changes = True )
243+
244+ def _raise_model_dump_error (* args , ** kwargs ):
245+ _ = args
246+ _ = kwargs
247+ raise HyperbrowserError ("custom model_dump failure" )
248+
249+ monkeypatch .setattr (
250+ UpdateSessionProfileParams , "model_dump" , _raise_model_dump_error
251+ )
252+
253+ async def run () -> None :
254+ with pytest .raises (
255+ HyperbrowserError , match = "custom model_dump failure"
256+ ) as exc_info :
257+ await manager .update_profile_params ("session-1" , params )
258+ assert exc_info .value .original_error is None
259+
260+ asyncio .run (run ())
261+
262+
167263def test_sync_update_profile_params_requires_argument_or_keyword ():
168264 manager = SyncSessionManager (_SyncClient ())
169265
0 commit comments