@@ -390,6 +390,50 @@ def on_page_success(response: dict) -> object:
390390 assert callback_attempts ["count" ] == 1
391391
392392
393+ def test_collect_paginated_results_fails_fast_when_on_page_success_raises ():
394+ page_attempts = {"count" : 0 }
395+
396+ def get_next_page (page : int ) -> dict :
397+ page_attempts ["count" ] += 1
398+ return {"current" : 1 , "total" : 1 , "items" : []}
399+
400+ with pytest .raises (HyperbrowserError , match = "on_page_success failed" ):
401+ collect_paginated_results (
402+ operation_name = "sync paginated callback exception" ,
403+ get_next_page = get_next_page ,
404+ get_current_page_batch = lambda response : response ["current" ],
405+ get_total_page_batches = lambda response : response ["total" ],
406+ on_page_success = lambda response : (_ for _ in ()).throw (ValueError ("boom" )),
407+ max_wait_seconds = 1.0 ,
408+ max_attempts = 5 ,
409+ retry_delay_seconds = 0.0001 ,
410+ )
411+
412+ assert page_attempts ["count" ] == 1
413+
414+
415+ def test_collect_paginated_results_fails_fast_when_page_batch_callback_raises ():
416+ page_attempts = {"count" : 0 }
417+
418+ def get_next_page (page : int ) -> dict :
419+ page_attempts ["count" ] += 1
420+ return {"current" : 1 , "total" : 1 , "items" : []}
421+
422+ with pytest .raises (HyperbrowserError , match = "get_current_page_batch failed" ):
423+ collect_paginated_results (
424+ operation_name = "sync paginated page-batch callback exception" ,
425+ get_next_page = get_next_page ,
426+ get_current_page_batch = lambda response : response ["missing" ], # type: ignore[index]
427+ get_total_page_batches = lambda response : response ["total" ],
428+ on_page_success = lambda response : None ,
429+ max_wait_seconds = 1.0 ,
430+ max_attempts = 5 ,
431+ retry_delay_seconds = 0.0001 ,
432+ )
433+
434+ assert page_attempts ["count" ] == 1
435+
436+
393437def test_collect_paginated_results_rejects_awaitable_current_page_callback_result ():
394438 with pytest .raises (
395439 HyperbrowserError ,
@@ -520,6 +564,58 @@ def on_page_success(response: dict) -> object:
520564 asyncio .run (run ())
521565
522566
567+ def test_collect_paginated_results_async_fails_fast_when_on_page_success_raises ():
568+ async def run () -> None :
569+ page_attempts = {"count" : 0 }
570+
571+ async def get_next_page (page : int ) -> dict :
572+ page_attempts ["count" ] += 1
573+ return {"current" : 1 , "total" : 1 , "items" : []}
574+
575+ with pytest .raises (HyperbrowserError , match = "on_page_success failed" ):
576+ await collect_paginated_results_async (
577+ operation_name = "async paginated callback exception" ,
578+ get_next_page = get_next_page ,
579+ get_current_page_batch = lambda response : response ["current" ],
580+ get_total_page_batches = lambda response : response ["total" ],
581+ on_page_success = lambda response : (_ for _ in ()).throw (
582+ ValueError ("boom" )
583+ ),
584+ max_wait_seconds = 1.0 ,
585+ max_attempts = 5 ,
586+ retry_delay_seconds = 0.0001 ,
587+ )
588+
589+ assert page_attempts ["count" ] == 1
590+
591+ asyncio .run (run ())
592+
593+
594+ def test_collect_paginated_results_async_fails_fast_when_page_batch_callback_raises ():
595+ async def run () -> None :
596+ page_attempts = {"count" : 0 }
597+
598+ async def get_next_page (page : int ) -> dict :
599+ page_attempts ["count" ] += 1
600+ return {"current" : 1 , "total" : 1 , "items" : []}
601+
602+ with pytest .raises (HyperbrowserError , match = "get_total_page_batches failed" ):
603+ await collect_paginated_results_async (
604+ operation_name = "async paginated page-batch callback exception" ,
605+ get_next_page = get_next_page ,
606+ get_current_page_batch = lambda response : response ["current" ],
607+ get_total_page_batches = lambda response : response ["missing" ], # type: ignore[index]
608+ on_page_success = lambda response : None ,
609+ max_wait_seconds = 1.0 ,
610+ max_attempts = 5 ,
611+ retry_delay_seconds = 0.0001 ,
612+ )
613+
614+ assert page_attempts ["count" ] == 1
615+
616+ asyncio .run (run ())
617+
618+
523619def test_collect_paginated_results_async_rejects_awaitable_current_page_callback_result ():
524620 async def run () -> None :
525621 with pytest .raises (
0 commit comments