autool/DroidBot/exceptions.py
2026-06-17 19:44:18 +08:00

81 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
DroidBot Exceptions Module
定义致命异常类型,供其他模块导入使用。
独立模块避免循环导入问题。
"""
import logging
logger = logging.getLogger(__name__)
class InputInterruptedException(Exception):
"""
Exception in InputManager
"""
pass
class ADBException(Exception):
"""
Exception in ADB connection
"""
pass
class AppCrashException(Exception):
"""
Exception raised when app crashes repeatedly (闪退异常)
Triggered when the app fails to restart multiple times consecutively.
"""
pass
class AppNeedUpdateException(Exception):
"""
Exception raised when app redirects to Google Play Store (需更新异常)
Triggered when the foreground package changes to com.android.vending.
"""
pass
class AppLaunchErrorException(Exception):
"""
Exception raised when app redirects to another app (启动异常-跳转)
Triggered when the foreground package changes to a third-party app.
"""
pass
class ExplorationStuckException(Exception):
"""
Exception raised when exploration is stuck (探索停滞异常)
Triggered when no new states are discovered for a prolonged period.
"""
pass
# 致命异常集合 - 遇到这些异常应立即中止并抛出
# 先定义基本异常,避免循环导入问题
# 其他模块可从此处导入使用: from .exceptions import FATAL_EXCEPTIONS
FATAL_EXCEPTIONS = (
ADBException, # ADB 断联
AppCrashException, # 应用闪退
AppNeedUpdateException, # 需更新跳转Google Play
AppLaunchErrorException, # 启动异常(跳转其他应用)
ExplorationStuckException, # 探索停滞
KeyboardInterrupt, # 用户手动中断
SystemExit, # 系统退出
)
# 导入 WDA 异常类 (iOS 相关) - 延迟导入避免循环依赖
try:
from .platforms.ios.wda.exceptions import (
MuxError, MuxConnectError, WDAError, WDAStuckError
)
# 仅 WDAStuckError多次恢复失败是致命异常
# 普通 WDA 异常由 IOSDevice._on_wda_failure() 处理,触发异步恢复
FATAL_EXCEPTIONS = FATAL_EXCEPTIONS + (WDAStuckError,)
# 导出普通 WDA 异常供 ios_start.py 等模块捕获使用
WDA_RECOVERABLE_EXCEPTIONS = (WDAError, MuxError, MuxConnectError)
except ImportError:
# wda 模块不可用,继续使用基本异常集合
logger.warning("WDA 异常导入失败,仅使用基本异常集合")
WDA_RECOVERABLE_EXCEPTIONS = ()