Skip to content

[feature request] Handle adb errors gracefully. #78

@dreirund

Description

@dreirund

I have installed tetherback version 0.9.1.

Error messages from adb are not cleanly displayed but result in a python exception -- I think they should be handled gracefully within the python script, adb error cleanly displayed, and then the script to exit with an appropriate exit code, without throwing a python exception.

Two examples:

tetherback -0 -v (Android system was bootet, no recovery environment):

tetherback v0.9.1
Found ADB version 1.0.41
Using default transfer method: adb exec-out pipe (--exec-out)
Device reports kernel 3.18.140-Redux-V2.05/cea733f601
/system/bin/sh: twrp: inaccessible or not found
Traceback (most recent call last):
  File "/usr/bin/tetherback", line 33, in <module>
    sys.exit(load_entry_point('tetherback==0.9.1', 'console_scripts', 'tetherback')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tetherback/tetherback.py", line 313, in main
    check_TWRP(p, adb, args.force)
  File "/usr/lib/python3.11/site-packages/tetherback/tetherback.py", line 88, in check_TWRP
    output = adb.check_output(('shell','twrp -v')).strip()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tetherback/adb_wrapper.py", line 35, in check_output
    return sp.check_output(self.adbcmd(adbargs), universal_newlines=un, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('adb', '-d', 'shell', 'twrp -v')' returned non-zero exit status 127.

tetherback -v -M -D -R -C -X android_expand (recovery environment was bootet):

[...]
Backup plan:

PARTITION NAME    FILENAME                 FORMAT
----------------  -----------------------  -----------------
android_expand    android_expand.emmc.win  gzipped raw image
boot              boot.emmc.win            gzipped raw image
recovery          recovery.emmc.win        gzipped raw image
cache             cache.f2fs.win           tar -cz -p
system            system.ext4.win          tar -cz -p
userdata          data.ext4.win            tar -cz -p

Saving backup images in ./twrp-backup-2023-08-19--12-34-05/ ...
Saving partition android_expand (mmcblk1p2), 121924 MiB uncompressed...
Traceback (most recent call last):
  File "/usr/bin/tetherback", line 33, in <module>
    sys.exit(load_entry_point('tetherback==0.9.1', 'console_scripts', 'tetherback')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tetherback/tetherback.py", line 338, in main
    backup_partition(adb, partmap[standard], bp, args.transport, backupdir, args.verify)
  File "/usr/lib/python3.11/site-packages/tetherback/tetherback.py", line 239, in backup_partition
    if not really_umount(adb, '/dev/block/'+pi.devname, pi.mountpoint):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tetherback/adb_stuff.py", line 32, in really_umount
    if adb.check_output(('shell','umount %s 2>/dev/null && echo ok' % dev)).strip():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tetherback/adb_wrapper.py", line 35, in check_output
    return sp.check_output(self.adbcmd(adbargs), universal_newlines=un, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('adb', '-d', 'shell', 'umount /dev/block/mmcblk1p2 2>/dev/null && echo ok')' returned non-zero exit status 1.

Regards!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions