Skip to content

Commit d93d514

Browse files
Normalize session profile update argument errors to HyperbrowserError
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent ee0b91e commit d93d514

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

hyperbrowser/client/managers/async_manager/session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,26 +191,26 @@ async def update_profile_params(
191191

192192
if isinstance(params, UpdateSessionProfileParams):
193193
if persist_changes is not None:
194-
raise TypeError(
194+
raise HyperbrowserError(
195195
"Pass either UpdateSessionProfileParams as the second argument or persist_changes=bool, not both."
196196
)
197197
params_obj = params
198198
elif isinstance(params, bool):
199199
if persist_changes is not None:
200-
raise TypeError(
200+
raise HyperbrowserError(
201201
"Pass either a boolean as the second argument or persist_changes=bool, not both."
202202
)
203203
self._warn_update_profile_params_boolean_deprecated()
204204
params_obj = UpdateSessionProfileParams(persist_changes=params)
205205
elif params is None:
206206
if persist_changes is None:
207-
raise TypeError(
207+
raise HyperbrowserError(
208208
"update_profile_params() requires either UpdateSessionProfileParams or persist_changes=bool."
209209
)
210210
self._warn_update_profile_params_boolean_deprecated()
211211
params_obj = UpdateSessionProfileParams(persist_changes=persist_changes)
212212
else:
213-
raise TypeError(
213+
raise HyperbrowserError(
214214
"update_profile_params() requires either UpdateSessionProfileParams or a boolean persist_changes."
215215
)
216216

hyperbrowser/client/managers/sync_manager/session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,26 +183,26 @@ def update_profile_params(
183183

184184
if isinstance(params, UpdateSessionProfileParams):
185185
if persist_changes is not None:
186-
raise TypeError(
186+
raise HyperbrowserError(
187187
"Pass either UpdateSessionProfileParams as the second argument or persist_changes=bool, not both."
188188
)
189189
params_obj = params
190190
elif isinstance(params, bool):
191191
if persist_changes is not None:
192-
raise TypeError(
192+
raise HyperbrowserError(
193193
"Pass either a boolean as the second argument or persist_changes=bool, not both."
194194
)
195195
self._warn_update_profile_params_boolean_deprecated()
196196
params_obj = UpdateSessionProfileParams(persist_changes=params)
197197
elif params is None:
198198
if persist_changes is None:
199-
raise TypeError(
199+
raise HyperbrowserError(
200200
"update_profile_params() requires either UpdateSessionProfileParams or persist_changes=bool."
201201
)
202202
self._warn_update_profile_params_boolean_deprecated()
203203
params_obj = UpdateSessionProfileParams(persist_changes=persist_changes)
204204
else:
205-
raise TypeError(
205+
raise HyperbrowserError(
206206
"update_profile_params() requires either UpdateSessionProfileParams or a boolean persist_changes."
207207
)
208208

tests/test_session_update_profile_params.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from hyperbrowser.client.managers.sync_manager.session import (
1010
SessionManager as SyncSessionManager,
1111
)
12+
from hyperbrowser.exceptions import HyperbrowserError
1213
from hyperbrowser.models.session import UpdateSessionProfileParams
1314

1415

@@ -86,7 +87,7 @@ def test_sync_update_profile_params_bool_deprecation_warning_only_emitted_once()
8687
def test_sync_update_profile_params_rejects_conflicting_arguments():
8788
manager = SyncSessionManager(_SyncClient())
8889

89-
with pytest.raises(TypeError, match="not both"):
90+
with pytest.raises(HyperbrowserError, match="not both"):
9091
manager.update_profile_params(
9192
"session-1",
9293
UpdateSessionProfileParams(persist_changes=True),
@@ -127,7 +128,7 @@ def test_async_update_profile_params_rejects_conflicting_arguments():
127128
manager = AsyncSessionManager(_AsyncClient())
128129

129130
async def run() -> None:
130-
with pytest.raises(TypeError, match="not both"):
131+
with pytest.raises(HyperbrowserError, match="not both"):
131132
await manager.update_profile_params(
132133
"session-1",
133134
UpdateSessionProfileParams(persist_changes=True),
@@ -140,5 +141,15 @@ async def run() -> None:
140141
def test_sync_update_profile_params_requires_argument_or_keyword():
141142
manager = SyncSessionManager(_SyncClient())
142143

143-
with pytest.raises(TypeError, match="requires either"):
144+
with pytest.raises(HyperbrowserError, match="requires either"):
144145
manager.update_profile_params("session-1")
146+
147+
148+
def test_async_update_profile_params_requires_argument_or_keyword():
149+
manager = AsyncSessionManager(_AsyncClient())
150+
151+
async def run() -> None:
152+
with pytest.raises(HyperbrowserError, match="requires either"):
153+
await manager.update_profile_params("session-1")
154+
155+
asyncio.run(run())

0 commit comments

Comments
 (0)