Skip to content

Commit

Permalink
Refactor exceptions handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anya497 committed Aug 6, 2024
1 parent deecefa commit c6bdb7a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions AIAgent/ml/play_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,13 @@ def play_game(
f"actual coverage: {game_result.actual_coverage_percent:.2f}"
)
map2result = Map2Result(game_map2svm, game_result)
except (FunctionTimedOut, Exception) as error:
if isinstance(error, FunctionTimedOut):
log_message = f"<{with_predictor.name()}> timeouted on map {game_map2svm.GameMap.MapName} with {error.timedOutAfter}s"
else:
log_message = f"<{with_predictor.name()}> failed on map {game_map2svm.GameMap.MapName}:\n{traceback.format_exc()}"
logging.warning(log_message)
FeatureConfig.SAVE_IF_FAIL_OR_TIMEOUT.save_model(
with_predictor.model(), with_name=f"{with_predictor.name()}"
)
map2result = Map2Result(game_map2svm, None)
except FunctionTimedOut as error:
log_message = f"<{with_predictor.name()}> timeouted on map {game_map2svm.GameMap.MapName} with {error.timedOutAfter}s"
except Exception:
log_message = f"<{with_predictor.name()}> failed on map {game_map2svm.GameMap.MapName}:\n{traceback.format_exc()}"
logging.warning(log_message)
FeatureConfig.SAVE_IF_FAIL_OR_TIMEOUT.save_model(
with_predictor.model(), with_name=f"{with_predictor.name()}"
)
map2result = Map2Result(game_map2svm, None)
return map2result

0 comments on commit c6bdb7a

Please sign in to comment.