Skip to content

Commit aa74a7c

Browse files
committed
Improve error messages for accessing the result of a graph run before it has finished
1 parent e4d384a commit aa74a7c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pydantic_graph/pydantic_graph/graph.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,15 @@ def is_ended(self):
542542
@property
543543
def result(self) -> RunEndT:
544544
if self._result is None:
545-
raise exceptions.GraphRuntimeError('GraphRun has not ended yet.')
545+
if self._started:
546+
raise exceptions.GraphRuntimeError(
547+
'This GraphRun has not yet ended. Continue iterating with `async for` or `GraphRun.next`'
548+
' to complete the run before accessing the result.'
549+
)
550+
else:
551+
raise exceptions.GraphRuntimeError(
552+
'This GraphRun has not been started. Did you forget to `await` the run?'
553+
)
546554
return self._result.data
547555

548556
async def next(

0 commit comments

Comments
 (0)