Improved error handling for SudoScript

This commit is contained in:
SimplifiedPrivacy 2026-11-03 16:55:25 -05:00
parent 4096196849
commit 728a6bd51c
2 changed files with 17 additions and 7 deletions

View file

@ -19,6 +19,7 @@ from core.models.Result import Result, ResultError
# wireguard_types = [SystemConnectionTypes.WIREGUARD, SessionConnectionTypes.WIREGUARD] # wireguard_types = [SystemConnectionTypes.WIREGUARD, SessionConnectionTypes.WIREGUARD]
from core.errors.logger import logger from core.errors.logger import logger
from core.errors.exceptions import SudoScript
# from core.errors.exceptions import * # from core.errors.exceptions import *
from core.errors.exceptions import FirewallError from core.errors.exceptions import FirewallError
from typing import Union, Optional, Callable from typing import Union, Optional, Callable
@ -50,7 +51,11 @@ def establish_connection(
# ========================================= # =========================================
if profile.connection.code in ("hysteria2", "vless"): if profile.connection.code in ("hysteria2", "vless"):
logger.info("Pulling encrypted proxies off the main flow..") logger.info("Pulling encrypted proxies off the main flow..")
return launch_encrypted_proxy(profile, connection_observer) try:
return launch_encrypted_proxy(profile, connection_observer)
except SudoScript as e:
logger.error(str(e))
return Result(valid=False, error_type=ResultError.SETUP_SINGBOX, message="The pre-req Singbox sudo wrappers are not setup, would you like to set it up?")
# ========================================= # =========================================
# SOCKS5 & WIREGUARD # SOCKS5 & WIREGUARD

View file

@ -1,3 +1,4 @@
from core.errors.exceptions import SudoScript
from core.services.helpers.install_dependencies import SUDO_SINGBOX_LOCATION from core.services.helpers.install_dependencies import SUDO_SINGBOX_LOCATION
from core.services.helpers.setup_sudo_scripts import is_singbox_wrapper_ready from core.services.helpers.setup_sudo_scripts import is_singbox_wrapper_ready
from core.services.networking.systemwide.encrypted_proxy.configure_singbox import configure_singbox from core.services.networking.systemwide.encrypted_proxy.configure_singbox import configure_singbox
@ -74,12 +75,16 @@ def launch_encrypted_proxy(
logger.info(f"Attempt {tries}: establishing connection to server {server_ip}") logger.info(f"Attempt {tries}: establishing connection to server {server_ip}")
connection_result = start_singbox( try:
profile_id=profile.id, connection_result = start_singbox(
server_ip=server_ip, profile_id=profile.id,
protocol_choice=profile.connection.code, server_ip=server_ip,
connection_observer=connection_observer protocol_choice=profile.connection.code,
) connection_observer=connection_observer
)
except SudoScript as e:
logger.error(str(e))
return Result(valid=False, error_type=ResultError.SETUP_SINGBOX, message="The pre-req Singbox sudo wrappers are not setup, would you like to set it up?")
if connection_result.valid: if connection_result.valid:
return connection_result return connection_result