mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-17 15:35:21 +02:00
bug fix: add exception handle
This commit is contained in:
parent
e27d97ee3c
commit
896932e02d
1 changed files with 23 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ from pydantic import BaseModel, Field
|
|||
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.roles import Role
|
||||
|
|
@ -299,9 +300,30 @@ class GameEnvironment(BaseModel, arbitrary_types_allowed=True):
|
|||
)
|
||||
self.update_event(events)
|
||||
return events
|
||||
|
||||
except Exception as e:
|
||||
### add: 异常的话结束当前流程,继续后续运行
|
||||
logger.error(f"Failed to retrieve Minecraft events: {str(e)}")
|
||||
raise {}
|
||||
time.sleep(3) # wait for mineflayer to exit
|
||||
info = {
|
||||
"task": self.current_task,
|
||||
"success": False,
|
||||
}
|
||||
# reset bot status here
|
||||
events = self.mf_instance.reset(
|
||||
options={
|
||||
"mode": "hard",
|
||||
"wait_ticks": 20,
|
||||
"inventory": self.events[-1][1]["inventory"],
|
||||
"equipment": self.events[-1][1]["status"]["equipment"],
|
||||
"position": self.events[-1][1]["status"]["position"],
|
||||
}
|
||||
)
|
||||
self.update_event(events)
|
||||
# use red color background to print the error
|
||||
logger.info("Your last round rollout terminated due to error:")
|
||||
logger.info(f"\033[41m{e}\033[0m")
|
||||
|
||||
|
||||
async def on_event_execute(self, *args):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue