Generate better error messages

This commit is contained in:
Nate Bowman
2026-11-11 23:57:14 -05:00
parent 5a5c6e1d3a
commit 20d4f5bd6c
2 changed files with 18 additions and 2 deletions

View File

@@ -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]

View File

@@ -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]