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 |
| 177 | Failed to boot recovery |
| 178 | Platform is not supported |
| 179 | Unexpected error |
| 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
def _fastboot_run(command: [str], serial: str = None) -> str:
def _fastboot_run(command: list[str], serial: str | None = None) -> str:
try:
cmd = ["fastboot"]
if not serial:
@ -19,13 +19,13 @@ def _fastboot_run(command: [str], serial: str = None) -> str:
console.log("Fastboot binary not found")
console.log("Exiting")
exit(1)
except subprocess.CalledProcessError:
except subprocess.TimeoutExpired:
raise exceptions.DeviceNotFound("Timed out")
else:
return fb_out.decode()
def list_devices() -> [str]:
def list_devices() -> list[str]:
return list(
filter(
lambda x: x != "",

View file

@ -256,6 +256,10 @@ def main() -> int:
console.log("Reflash your rom and try again")
fastboot.reboot(serial)
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"):
try:
adb.wait_for(serial, state="recovery")
@ -296,6 +300,10 @@ def main() -> int:
console.log("Reflash your rom and try again")
fastboot.reboot(serial)
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"):
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 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 esp fat32 {linux_end}GB {maxsize}GB",
f"parted -s /dev/block/sda set 33 esp on"
f"parted -s /dev/block/sda mkpart esp fat32 {linux_end}GB {maxsize}GB"
]
for cmd in cmds:
device.shell(cmd)