From 35a746796923cfa7e4568057ea83985e34d18d72 Mon Sep 17 00:00:00 2001 From: Daniel Toyama Date: Thu, 30 Nov 2023 05:53:17 -0800 Subject: [PATCH] Remove unnecessary decorator for `BaseSimulator.launch()`. This decorator was used for many functions, but we currently used it only during `launch()`, so it only adds unnecessary complexity. This change moves its main `try`/`except` logic inside `launch()` to simplify things. PiperOrigin-RevId: 586650107 --- .../components/simulators/base_simulator.py | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/android_env/components/simulators/base_simulator.py b/android_env/components/simulators/base_simulator.py index 593d3a6..5a45fc7 100644 --- a/android_env/components/simulators/base_simulator.py +++ b/android_env/components/simulators/base_simulator.py @@ -25,21 +25,6 @@ import numpy as np -def _print_logs_on_exception(func): - """Decorator function for printing simulator logs upon any exception.""" - def wrapper(*args, **kwargs): - try: - return func(*args, **kwargs) - except Exception as error: - # Calls self.get_logs since self is the first arg. - for line in args[0].get_logs().splitlines(): - logging.error(line) - raise errors.SimulatorError( - 'Exception caught in simulator. Please see the simulator logs ' - 'above for more details.') from error - return wrapper - - class BaseSimulator(metaclass=abc.ABCMeta): """An interface for communicating with an Android simulator.""" @@ -75,12 +60,19 @@ def create_adb_controller(self) -> adb_controller.AdbController: def create_log_stream(self) -> log_stream.LogStream: """Creates a stream of logs from the simulator.""" - @_print_logs_on_exception def launch(self) -> None: """Starts the simulator.""" self._num_launch_attempts += 1 - self._launch_impl() + try: + self._launch_impl() + except Exception as error: + for line in self.get_logs().splitlines(): + logging.error(line) + raise errors.SimulatorError( + 'Exception caught in simulator. Please see the simulator logs ' + 'above for more details.' + ) from error @abc.abstractmethod def _launch_impl(self) -> None: