Skip to content

Commit c30966c

Browse files
committed
better err handling
1 parent e9665fb commit c30966c

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

haystack/core/pipeline/async_pipeline.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,19 @@ async def __anext__(self) -> Any:
5454

5555
@property
5656
def result(self) -> dict[str, Any]:
57-
"""Final pipeline output dict. Raises if accessed before iteration completes."""
57+
"""
58+
Final pipeline output dict, available only after a successful, complete run.
59+
60+
Raises a clear `RuntimeError` for each non-success state (not finished, cancelled, failed)
61+
so the caller does not need to inspect the underlying task to interpret the outcome.
62+
"""
5863
if self._task is None or not self._task.done():
59-
raise RuntimeError("Pipeline still running. Iterate this handle to completion first.")
64+
raise RuntimeError("Pipeline has not finished; iterate the handle first.")
65+
if self._task.cancelled():
66+
raise RuntimeError("Pipeline was cancelled; no result available.")
67+
exc = self._task.exception()
68+
if exc is not None:
69+
raise RuntimeError("Pipeline failed; no result available.") from exc
6070
return self._task.result()
6171

6272
async def aclose(self) -> None:

0 commit comments

Comments
 (0)