Skip to content

Commit

Permalink
Fix exception message formatting (#136)
Browse files Browse the repository at this point in the history
* Fix exception message formatting

* Remove unnecessary 'else:' block
  • Loading branch information
JeffLIrion committed Nov 26, 2020
1 parent 02dfd15 commit 94f0aea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions adb_shell/adb_device.py
Expand Up @@ -769,10 +769,11 @@ def _read(self, expected_cmds, adb_info):
break

if time.time() - start > adb_info.read_timeout_s:
raise exceptions.InvalidCommandError("Never got one of the expected responses: %s (transport_timeout_s = %d, read_timeout_s = %d" % (expected_cmds, adb_info.transport_timeout_s, adb_info.read_timeout_s))
raise exceptions.InvalidCommandError("Never got one of the expected responses: %s (transport_timeout_s = %f, read_timeout_s = %f)" % (expected_cmds, adb_info.transport_timeout_s, adb_info.read_timeout_s))

data = bytearray()

if data_length > 0:
data = bytearray()
while data_length > 0:
temp = self._transport.bulk_read(data_length, adb_info.transport_timeout_s)
_LOGGER.debug("bulk_read(%d): %.1000s", data_length, repr(temp))
Expand All @@ -784,9 +785,6 @@ def _read(self, expected_cmds, adb_info):
if actual_checksum != data_checksum:
raise exceptions.InvalidChecksumError('Received checksum {0} != {1}'.format(actual_checksum, data_checksum))

else:
data = bytearray()

return command, arg0, arg1, bytes(data)

def _read_until(self, expected_cmds, adb_info):
Expand Down Expand Up @@ -833,7 +831,7 @@ def _read_until(self, expected_cmds, adb_info):
break

if time.time() - start > adb_info.read_timeout_s:
raise exceptions.InvalidCommandError("Never got one of the expected responses: %s (transport_timeout_s = %d, read_timeout_s = %d" % (expected_cmds, adb_info.transport_timeout_s, adb_info.read_timeout_s))
raise exceptions.InvalidCommandError("Never got one of the expected responses: %s (transport_timeout_s = %f, read_timeout_s = %f)" % (expected_cmds, adb_info.transport_timeout_s, adb_info.read_timeout_s))

# Ignore CLSE responses to previous commands
# https://github.com/JeffLIrion/adb_shell/pull/14
Expand Down
10 changes: 4 additions & 6 deletions adb_shell/adb_device_async.py
Expand Up @@ -764,10 +764,11 @@ async def _read(self, expected_cmds, adb_info):
break

if time.time() - start > adb_info.read_timeout_s:
raise exceptions.InvalidCommandError("Never got one of the expected responses: %s (transport_timeout_s = %d, read_timeout_s = %d" % (expected_cmds, adb_info.transport_timeout_s, adb_info.read_timeout_s))
raise exceptions.InvalidCommandError("Never got one of the expected responses: %s (transport_timeout_s = %f, read_timeout_s = %f)" % (expected_cmds, adb_info.transport_timeout_s, adb_info.read_timeout_s))

data = bytearray()

if data_length > 0:
data = bytearray()
while data_length > 0:
temp = await self._transport.bulk_read(data_length, adb_info.transport_timeout_s)
_LOGGER.debug("bulk_read(%d): %.1000s", data_length, repr(temp))
Expand All @@ -779,9 +780,6 @@ async def _read(self, expected_cmds, adb_info):
if actual_checksum != data_checksum:
raise exceptions.InvalidChecksumError('Received checksum {0} != {1}'.format(actual_checksum, data_checksum))

else:
data = bytearray()

return command, arg0, arg1, bytes(data)

async def _read_until(self, expected_cmds, adb_info):
Expand Down Expand Up @@ -828,7 +826,7 @@ async def _read_until(self, expected_cmds, adb_info):
break

if time.time() - start > adb_info.read_timeout_s:
raise exceptions.InvalidCommandError("Never got one of the expected responses: %s (transport_timeout_s = %d, read_timeout_s = %d" % (expected_cmds, adb_info.transport_timeout_s, adb_info.read_timeout_s))
raise exceptions.InvalidCommandError("Never got one of the expected responses: %s (transport_timeout_s = %f, read_timeout_s = %f)" % (expected_cmds, adb_info.transport_timeout_s, adb_info.read_timeout_s))

# Ignore CLSE responses to previous commands
# https://github.com/JeffLIrion/adb_shell/pull/14
Expand Down

0 comments on commit 94f0aea

Please sign in to comment.