Skip to content

Commit f576bac

Browse files
kenjitoyamacopybara-github
authored andcommitted
Remove unnecessary debug information from error.
`latest_error.{stdout,stderr}` should be defined when raising the exception, but `pytype` still complains about `attribute-error`. Since this information is already logged, I think it's OK to remove it from the error. PiperOrigin-RevId: 836246226
1 parent 800be08 commit f576bac

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

android_env/components/adb_controller.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ def execute_command(
124124
command = self.command_prefix(include_device_name=device_specific) + args
125125
command_str = 'adb ' + ' '.join(command[1:])
126126

127-
n_retries = 2
128-
n_tries = 1
127+
n_tries = 2
129128
latest_error = None
130-
while n_tries <= n_retries:
129+
for i in range(n_tries):
131130
try:
132131
logging.info('Executing ADB command: [%s]', command_str)
133132
cmd_output = subprocess.check_output(
@@ -140,7 +139,8 @@ def execute_command(
140139
return cmd_output
141140
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
142141
logging.exception(
143-
'Failed to execute ADB command (try %r of 3): [%s]',
142+
'Failed to execute ADB command (try %d of %d): [%s]',
143+
i + 1,
144144
n_tries,
145145
command_str,
146146
)
@@ -152,14 +152,11 @@ def execute_command(
152152
logging.error('**stderr**:')
153153
for line in e.stderr.splitlines():
154154
logging.error(' %s', line)
155-
n_tries += 1
156155
latest_error = e
157-
if device_specific and n_tries <= n_retries:
156+
if device_specific and i < n_tries - 1:
158157
self._restart_server(timeout=timeout)
159158

160159
raise errors.AdbControllerError(
161160
f'Error executing adb command: [{command_str}]\n'
162-
f'Caused by: {latest_error}\n'
163-
f'adb stdout: [{latest_error.stdout}]\n'
164-
f'adb stderr: [{latest_error.stderr}]'
161+
f'Caused by: {latest_error}'
165162
) from latest_error

0 commit comments

Comments
 (0)