<#1208 fix(runtime): surface load-time errors in t...
# flyte-github
a
#1208 fix(runtime): surface load-time errors in task UI instead of empty message Pull request opened by kumare3 Problem When a task fails while loading — e.g. a top-level
ModuleNotFoundError
because a dependency is present in the local env but missing from the task image — the container dies in
_download_and_load_task
, which runs before the
contextual_run
wrapper that writes the error document (
error.pb
). With no
error.pb
, the backend has no error message to display, so the task UI shows only:
Copy code
[primary] terminated with exit code (1). Reason [Error]. Message:
.
The real
ModuleNotFoundError
— including the nice diagnostics
load_task
already builds (cwd + file listing) — is buried at the very bottom of the task logs. This is the issue surfaced in the support thread. Root cause
entrypoints.py
loads the task before the error-capturing wrapper:
Copy code
task = await _download_and_load_task(...)        # raises here -> no error.pb
await contextual_run(extract_download_run_upload, ...)   # upload_error() lives in here
An import that fails inside the task body is caught by
convert_and_run
and written to
error.pb
(UI shows it correctly). An import that fails at module top level fails during load and bypasses that path entirely. Fix Wrap the load step in `load_and_run_task`: on failure, convert the exception to an error document and
upload_error()
it to the task's output path, then re-raise (preserving the non-zero exit). The actual reason now appears in the UI's
Message:
field. Tests •
test_load_failure_uploads_error_document
— load failure uploads an error document carrying the real message/code, then re-raises. •
test_load_failure_without_output_path_still_raises
— no output path → still propagates, no upload attempted. Reproduction
examples/basics/module_not_found.py
is a deliberate repro (top-level import missing from the image, custom pod template so the
[primary]
container name matches). Before this fix it yields the empty message above; with the fix the UI shows
ModuleNotFoundError: No module named 'emoji'
.
Copy code
pip install emoji        # local-only, so the task can be submitted
flyte run examples/basics/module_not_found.py main
🤖 Generated with Claude Code flyteorg/flyte-sdk