Skip to content

Commit

Permalink
feat: remove unused exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
adeprez committed Oct 3, 2024
1 parent 5113f98 commit 6d226cf
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
PossibleInteractionsByXpath,
InteractionType,
)
from lavague.sdk.exceptions import (
NoElementException,
AmbiguousException,
)
import time


Expand Down Expand Up @@ -207,14 +203,6 @@ def exec_code(
)
elif action_name == "wait":
self.perform_wait(item["action"]["args"]["duration"])
elif action_name == "failNoElement":
raise NoElementException(
"No element: " + item["action"]["args"]["value"]
)
elif action_name == "failAmbiguous":
raise AmbiguousException(
"Ambiguous: " + item["action"]["args"]["value"]
)

self.wait_for_idle()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
InteractionType,
DOMNode,
)
from lavague.sdk.exceptions import (
CannotBackException,
NoElementException,
AmbiguousException,
)
from lavague.sdk.exceptions import CannotBackException
from PIL import Image
from io import BytesIO
from selenium.webdriver.chrome.options import Options
Expand Down Expand Up @@ -297,10 +293,6 @@ def exec_code(
xpath,
ScrollDirection.from_string(args.get("value", "DOWN")),
)
case "failNoElement":
raise NoElementException("No element: " + args["value"])
case "failAmbiguous":
raise AmbiguousException("Ambiguous: " + args["value"])
case _:
raise ValueError(f"Unknown action: {action_name}")

Expand Down
34 changes: 2 additions & 32 deletions lavague-sdk/lavague/sdk/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
from typing import Optional


class NavigationException(Exception):
class DriverException(Exception):
pass


class ExtractorException(Exception):
pass


class CannotBackException(NavigationException):
class CannotBackException(DriverException):
def __init__(self, message="History root reached, cannot go back"):
super().__init__(message)


class RetrievalException(NavigationException):
pass


class NoElementException(RetrievalException):
def __init__(self, message="No element found"):
super().__init__(message)


class AmbiguousException(RetrievalException):
def __init__(self, message="Multiple elements could match"):
super().__init__(message)


class HallucinatedException(RetrievalException):
def __init__(self, xpath: str, message: Optional[str] = None):
super().__init__(message or f"Element was hallucinated: {xpath}")


class ElementOutOfContextException(RetrievalException):
def __init__(self, xpath: str, message: Optional[str] = None):
super().__init__(message or f"Element exists but was not in context: {xpath}")

0 comments on commit 6d226cf

Please sign in to comment.