Skip to content

Commit 722e54e

Browse files
committed
Raise understandable exception when failing to pull
Fixes google#107
1 parent c610a56 commit 722e54e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

adb/filesync_protocol.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class PushFailedError(Exception):
4646
"""Pushing a file failed for some reason."""
4747

4848

49+
class PullFailedError(Exception):
50+
"""Pulling a file failed for some reason."""
51+
52+
4953
DeviceFile = collections.namedtuple('DeviceFile', [
5054
'filename', 'mode', 'size', 'mtime'])
5155

@@ -85,13 +89,16 @@ def Pull(cls, connection, filename, dest_file, progress_callback):
8589
next(progress)
8690

8791
cnxn = FileSyncConnection(connection, b'<2I')
88-
cnxn.Send(b'RECV', filename)
89-
for cmd_id, _, data in cnxn.ReadUntil((b'DATA',), b'DONE'):
90-
if cmd_id == b'DONE':
91-
break
92-
dest_file.write(data)
93-
if progress_callback:
94-
progress.send(len(data))
92+
try:
93+
cnxn.Send(b'RECV', filename)
94+
for cmd_id, _, data in cnxn.ReadUntil((b'DATA',), b'DONE'):
95+
if cmd_id == b'DONE':
96+
break
97+
dest_file.write(data)
98+
if progress_callback:
99+
progress.send(len(data))
100+
except usb_exceptions.CommonUsbError as e:
101+
raise PullFailedError('Unable to pull file %s due to: %s' % (filename, e))
95102

96103
@classmethod
97104
def _HandleProgress(cls, progress_callback):

0 commit comments

Comments
 (0)