Add unexpected error handler

This commit is contained in:
timoxa0 2024-05-20 08:48:59 +05:00
parent f4c68e6bbb
commit ac1f25ccbc
4 changed files with 14 additions and 6 deletions

View file

@ -17,5 +17,6 @@
| 176 | Failed to patch boot image | | 176 | Failed to patch boot image |
| 177 | Failed to boot recovery | | 177 | Failed to boot recovery |
| 178 | Platform is not supported | | 178 | Platform is not supported |
| 179 | Unexpected error |
| 253 | User cancel | | 253 | User cancel |
| 254 | Is it nabu? | | 254 | Is it nabu? |

View file

@ -5,7 +5,7 @@ from . import files, exceptions
from .utils import logger, console from .utils import logger, console
def _fastboot_run(command: [str], serial: str = None) -> str: def _fastboot_run(command: list[str], serial: str | None = None) -> str:
try: try:
cmd = ["fastboot"] cmd = ["fastboot"]
if not serial: if not serial:
@ -19,13 +19,13 @@ def _fastboot_run(command: [str], serial: str = None) -> str:
console.log("Fastboot binary not found") console.log("Fastboot binary not found")
console.log("Exiting") console.log("Exiting")
exit(1) exit(1)
except subprocess.CalledProcessError: except subprocess.TimeoutExpired:
raise exceptions.DeviceNotFound("Timed out") raise exceptions.DeviceNotFound("Timed out")
else: else:
return fb_out.decode() return fb_out.decode()
def list_devices() -> [str]: def list_devices() -> list[str]:
return list( return list(
filter( filter(
lambda x: x != "", lambda x: x != "",

View file

@ -256,6 +256,10 @@ def main() -> int:
console.log("Reflash your rom and try again") console.log("Reflash your rom and try again")
fastboot.reboot(serial) fastboot.reboot(serial)
return 177 return 177
except subprocess.CalledProcessError as e:
console.log("Fastboot error. Please contact developer")
console.log("Executed command", e.cmd)
return 179
with console.status("[cyan]Waiting for device", spinner="line", spinner_style="white"): with console.status("[cyan]Waiting for device", spinner="line", spinner_style="white"):
try: try:
adb.wait_for(serial, state="recovery") adb.wait_for(serial, state="recovery")
@ -296,6 +300,10 @@ def main() -> int:
console.log("Reflash your rom and try again") console.log("Reflash your rom and try again")
fastboot.reboot(serial) fastboot.reboot(serial)
return 177 return 177
except subprocess.CalledProcessError as e:
console.log("Fastboot error. Please contact developer")
console.log("Executed command", e.cmd)
return 179
with console.status("[cyan]Waiting for device", spinner="line", spinner_style="white"): with console.status("[cyan]Waiting for device", spinner="line", spinner_style="white"):
try: try:

View file

@ -91,8 +91,7 @@ def repartition(serial: str, size: int, percents=False) -> None:
f"parted -s /dev/block/sda rm 31", f"parted -s /dev/block/sda rm 31",
f"parted -s /dev/block/sda mkpart userdata ext4 10.9GB {userdata_end}GB", f"parted -s /dev/block/sda mkpart userdata ext4 10.9GB {userdata_end}GB",
f"parted -s /dev/block/sda mkpart linux ext4 {userdata_end}GB {linux_end}GB", f"parted -s /dev/block/sda mkpart linux ext4 {userdata_end}GB {linux_end}GB",
f"parted -s /dev/block/sda mkpart esp fat32 {linux_end}GB {maxsize}GB", f"parted -s /dev/block/sda mkpart esp fat32 {linux_end}GB {maxsize}GB"
f"parted -s /dev/block/sda set 33 esp on"
] ]
for cmd in cmds: for cmd in cmds:
device.shell(cmd) device.shell(cmd)