mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
🎨 Updated error message (#345)
This commit is contained in:
@@ -5,7 +5,7 @@ from environs import Env
|
||||
from loguru import logger
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.exceptions import AppNotFoundError, PatchesJsonLoadError, PatchingFailedError, UnknownError
|
||||
from src.exceptions import AppNotFoundError, BuilderError, PatchesJsonLoadError, PatchingFailedError
|
||||
from src.parser import Parser
|
||||
from src.patches import Patches
|
||||
from src.utils import check_java, extra_downloads
|
||||
@@ -40,8 +40,8 @@ def main() -> None:
|
||||
logger.exception("Patches.json not found")
|
||||
except PatchingFailedError as e:
|
||||
logger.exception(e)
|
||||
except UnknownError as e:
|
||||
logger.exception(f"Failed to build {app} because of {e}")
|
||||
except BuilderError as e:
|
||||
logger.exception(f"Failed to build {possible_app} because of {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -24,7 +24,7 @@ from src.exceptions import (
|
||||
APKMirrorIconScrapError,
|
||||
APKMonkIconScrapError,
|
||||
APKPureIconScrapError,
|
||||
UnknownError,
|
||||
BuilderError,
|
||||
)
|
||||
from src.patches import Patches
|
||||
from src.utils import apkmirror_status_check, bs4_parser, handle_request_response, request_header
|
||||
@@ -47,7 +47,7 @@ def apkcombo_scrapper(package_name: str) -> str:
|
||||
raise APKComboIconScrapError(url=apkcombo_url)
|
||||
url = icon_element.get("data-src")
|
||||
return re.sub(r"=.*$", "", url) # type: ignore[arg-type]
|
||||
except UnknownError as e:
|
||||
except BuilderError as e:
|
||||
raise APKComboIconScrapError(url=apkcombo_url) from e
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ def gplay_icon_scrapper(package_name: str) -> str:
|
||||
package_name,
|
||||
)["icon"]
|
||||
)
|
||||
except UnknownError as e:
|
||||
except BuilderError as e:
|
||||
raise GooglePlayScraperException from e
|
||||
|
||||
|
||||
@@ -135,11 +135,10 @@ def apkpure_scrapper(package_name: str) -> str:
|
||||
soup = BeautifulSoup(r.text, bs4_parser)
|
||||
search_result = soup.find_all(class_="brand-info-top")
|
||||
for brand_info in search_result:
|
||||
icon_element = brand_info.find(class_="icon")
|
||||
if icon_element:
|
||||
if icon_element := brand_info.find(class_="icon"):
|
||||
return str(icon_element.get("src"))
|
||||
raise APKPureIconScrapError(url=apkpure_url)
|
||||
except UnknownError as e:
|
||||
except BuilderError as e:
|
||||
raise APKPureIconScrapError(url=apkpure_url) from e
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ from loguru import logger
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.downloader.sources import apk_sources
|
||||
from src.exceptions import DownloadError, PatchingFailedError, UnknownError
|
||||
from src.exceptions import BuilderError, DownloadError, PatchingFailedError
|
||||
from src.utils import slugify
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ class APP(object):
|
||||
for resource_name, future in futures.items():
|
||||
try:
|
||||
self.resource[resource_name] = future.result()
|
||||
except UnknownError as e:
|
||||
except BuilderError as e:
|
||||
raise PatchingFailedError(e) from e
|
||||
|
||||
@staticmethod
|
||||
|
||||
+25
-9
@@ -2,7 +2,17 @@
|
||||
from typing import Any, Self
|
||||
|
||||
|
||||
class APKMirrorIconScrapError(Exception):
|
||||
class BuilderError(Exception):
|
||||
"""Base class for all the project errors."""
|
||||
|
||||
message = "Default Error message."
|
||||
|
||||
def __str__(self: Self) -> str:
|
||||
"""Return error message."""
|
||||
return self.message
|
||||
|
||||
|
||||
class APKMirrorIconScrapError(BuilderError):
|
||||
"""Exception raised when the icon cannot be scraped from apkmirror."""
|
||||
|
||||
def __init__(self: Self, *args: Any, **kwargs: Any) -> None:
|
||||
@@ -30,11 +40,11 @@ class APKMonkIconScrapError(APKMirrorIconScrapError):
|
||||
"""Exception raised when the icon cannot be scraped from apkmonk."""
|
||||
|
||||
|
||||
class DownloadError(Exception):
|
||||
class DownloadError(BuilderError):
|
||||
"""Generic Download failure."""
|
||||
|
||||
def __init__(self: Self, *args: Any, **kwargs: Any) -> None:
|
||||
"""Initialize the APKMirrorAPKDownloadFailure exception.
|
||||
"""Initialize the DownloadFailure exception.
|
||||
|
||||
Args:
|
||||
----
|
||||
@@ -45,6 +55,11 @@ class DownloadError(Exception):
|
||||
super().__init__(*args)
|
||||
self.url = kwargs.get("url", None)
|
||||
|
||||
def __str__(self: Self) -> str:
|
||||
"""Exception message."""
|
||||
base_message = super().__str__()
|
||||
return f"Message - {base_message} Url - {self.url}"
|
||||
|
||||
|
||||
class APKDownloadError(DownloadError):
|
||||
"""Exception raised when the apk cannot be scraped."""
|
||||
@@ -74,15 +89,15 @@ class APKSosAPKDownloadError(APKDownloadError):
|
||||
"""Exception raised when downloading an APK from apksos failed."""
|
||||
|
||||
|
||||
class PatchingFailedError(Exception):
|
||||
class PatchingFailedError(BuilderError):
|
||||
"""Patching Failed."""
|
||||
|
||||
|
||||
class AppNotFoundError(ValueError):
|
||||
class AppNotFoundError(BuilderError):
|
||||
"""Not a valid Revanced App."""
|
||||
|
||||
|
||||
class PatchesJsonLoadError(ValueError):
|
||||
class PatchesJsonLoadError(BuilderError):
|
||||
"""Failed to load patches json."""
|
||||
|
||||
def __init__(self: Self, *args: Any, **kwargs: Any) -> None:
|
||||
@@ -97,6 +112,7 @@ class PatchesJsonLoadError(ValueError):
|
||||
super().__init__(*args)
|
||||
self.file_name = kwargs.get("file_name", None)
|
||||
|
||||
|
||||
class UnknownError(Exception):
|
||||
"""Some unknown error."""
|
||||
def __str__(self: Self) -> str:
|
||||
"""Exception message."""
|
||||
base_message = super().__str__()
|
||||
return f"Message - {base_message} Url - {self.file_name}"
|
||||
|
||||
Reference in New Issue
Block a user