Skip to content

Commit af8a995

Browse files
refactor: handle autodelete errors directly without exceptions
- Replaced exception raising in autodelete result handling with direct error handling - Session errors trigger retry by continuing the while loop - WebUI errors that can be retried also continue the loop - Service unavailable returns error code 1 - Other errors return appropriate ADT results or error codes - Removed unused PyiCloud2SARequiredException import - All tests pass, mypy strict mode passes
1 parent 4ef1463 commit af8a995

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/icloudpd/base.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
from pyicloud_ipd.asset_version import add_suffix_to_filename, calculate_version_filename
5757
from pyicloud_ipd.base import PyiCloudService
5858
from pyicloud_ipd.exceptions import (
59-
PyiCloud2SARequiredException,
6059
PyiCloudAPIResponseException,
6160
PyiCloudConnectionErrorException,
6261
PyiCloudServiceNotActivatedException,
@@ -1558,13 +1557,31 @@ def should_break(counter: Counter) -> bool:
15581557
case AutodeleteSuccess():
15591558
pass # Success, continue
15601559
case Response2SARequired(account_name):
1561-
raise PyiCloud2SARequiredException(account_name)
1560+
return Response2SARequired(account_name)
15621561
case ResponseServiceNotActivated(reason, code):
1563-
raise PyiCloudServiceNotActivatedException(reason, code)
1562+
return ResponseServiceNotActivated(reason, code)
15641563
case ResponseAPIError(reason, code):
1565-
raise PyiCloudAPIResponseException(reason, code)
1564+
logger.info(f"{reason} ({code})")
1565+
# Check if it's a session error that requires re-authentication
1566+
if "Invalid global session" in reason:
1567+
dump_responses(logger.debug, captured_responses)
1568+
# For autodelete, we'll continue the while loop for retry
1569+
continue
1570+
dump_responses(logger.debug, captured_responses)
1571+
# webui will display error and wait for password again
1572+
if (
1573+
PasswordProvider.WEBUI in global_config.password_providers
1574+
or global_config.mfa_provider == MFAProvider.WEBUI
1575+
) and update_auth_error_in_webui(
1576+
status_exchange, str(f"{reason} ({code})")
1577+
):
1578+
# retry if it was during auth
1579+
continue
1580+
return 1
15661581
case ResponseServiceUnavailable(reason):
1567-
raise PyiCloudServiceUnavailableException(reason)
1582+
logger.info(reason)
1583+
dump_responses(logger.debug, captured_responses)
1584+
return 1
15681585
else:
15691586
pass
15701587
except (

0 commit comments

Comments
 (0)