Skip to content

Commit 4dece0e

Browse files
committed
fix: raise exception if run fails
Signed-off-by: Donnie Adams <[email protected]>
1 parent 05f265e commit 4dece0e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

gptscript/run.py

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ async def text(self) -> str:
5757
self._err = "Run was aborted"
5858
else:
5959
self._err = str(e)
60+
61+
raise Exception(self._err)
6062
finally:
6163
self._task = None
6264

tests/test_gptscript.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,11 @@ async def abort_run(run: Run, e: CallFrame | RunFrame | PromptFrame):
152152

153153
run = gptscript.evaluate(ToolDef(instructions="What is the capital of the united states?"),
154154
Options(disableCache=True), event_handlers=[abort_run])
155+
try:
156+
await run.text()
157+
except Exception as e:
158+
assert "Run was aborted" in str(e), "Unexpected output from abort_run"
155159

156-
assert "Run was aborted" in await run.text(), "Unexpected output from abort_run"
157160
assert RunState.Error == run.state(), "Unexpected run state after aborting"
158161

159162

0 commit comments

Comments
 (0)