Implement Apex Agent MVP scaffold
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from core.errors import (
|
||||
DeviceNotFoundError,
|
||||
DeviceOfflineError,
|
||||
ElementNotFoundError,
|
||||
DriverError,
|
||||
)
|
||||
|
||||
|
||||
def semantic_error(exc: Exception) -> str:
|
||||
if isinstance(exc, DeviceOfflineError):
|
||||
return "device offline"
|
||||
if isinstance(exc, DeviceNotFoundError):
|
||||
return "device not found"
|
||||
if isinstance(exc, ElementNotFoundError):
|
||||
return "element not found"
|
||||
if isinstance(exc, DriverError):
|
||||
return "driver error"
|
||||
return "operation failed"
|
||||
|
||||
|
||||
def call_with_semantic_errors(func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as exc:
|
||||
return {"ok": False, "error": semantic_error(exc)}
|
||||
|
||||
Reference in New Issue
Block a user