[env] Include last error on init failure.
@@ -676,11 +676,6 @@ class CompilerEnv(gym.Env):
If no aciton space is provided, the default action space is used.
:return: The initial observation.
"""
- if retry_count > self._connection_settings.init_max_attempts:
- raise OSError(
- f"Failed to reset environment after {retry_count - 1} attempts"
- )
-
# Start a new service if required.
if self.service is None:
self.service = CompilerGymServiceConnection(
@@ -723,6 +718,13 @@ class CompilerEnv(gym.Env):
self.logger.warning("%s on reset(): %s", type(e).__name__, e)
self.service.close()
self.service = None
+
+ if retry_count >= self._connection_settings.init_max_attempts:
+ raise OSError(
+ f"Failed to reset environment after {retry_count - 1} attempts.\n"
+ f"Last error ({type(e).__name__}): {e}"
+ ) from e
+ else:
return self.reset(
benchmark=benchmark,
action_space=action_space,
