From 20d4f5bd6c046a36b3bfd3f7de53a10d442ed6c2 Mon Sep 17 00:00:00 2001 From: Nate Bowman Date: Wed, 11 Nov 2026 23:57:14 -0500 Subject: [PATCH] Generate better error messages --- aoe/gameplay.py | 7 ++++++- aoe/world.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/aoe/gameplay.py b/aoe/gameplay.py index 752faca..d5868f3 100644 --- a/aoe/gameplay.py +++ b/aoe/gameplay.py @@ -136,7 +136,12 @@ class Gameplay(): def _handle_actions(self): for func, args in self.actions[self.world.current_time]: - func(*args) + try: + func(*args) + except Exception as e: + raise type(e)( + f'Error in {func.__name__}{args}' + f' at time {self.world.current_time}.') from e del self.actions[self.world.current_time] diff --git a/aoe/world.py b/aoe/world.py index 778690b..4d8c8a5 100644 --- a/aoe/world.py +++ b/aoe/world.py @@ -528,7 +528,18 @@ class World(): def _handle_events(self): for func, args in self.events[self.current_time]: - func(*args) + try: + func(*args) + except Exception as e: + raise type(e)( + f'Error in {func.__name__}{args}' + f' at time {self.current_time}.' + f' Note that the actual gameplay command that caused' + f' the error may not have been issued at' + f' {self.current_time} -- the action may have been' + f' delayed until that time while' + f' waiting in a queue') from e + del self.events[self.current_time]