acoustic-carpenter-78188
05/21/2026, 4:13 PMflyte deploy <dir> and flyte deploy <file> both invoke
flyte._utils.module_loader.load_python_modules. When a user .py file
fails at import time with ModuleNotFoundError (missing third-party
dep), SyntaxError, NameError, KeyError-via-bad-import, TypeError,
etc., the bare exception bubbled past the Sentry capture_errors
decorator in flyte/cli/_deploy.py and landed in Sentry as an SDK
crash — even though the code that failed was in the user's workflow,
not in flyte.
Changes
1. flyte._utils.module_loader.load_python_modules — catch
ImportError / SyntaxError / NameError / AttributeError /
TypeError / ValueError raised during `importlib.import_module`:
• Single-file path: wrap in flyte.errors.ModuleLoadError
(a RuntimeUserError), preserving the original traceback via
from e, so the CLI surfaces an actionable message and the
exception type itself signals "user error".
• Directory path: record the failure in failed_paths so deploy
either warns or aborts via --ignore-load-errors, matching how
pre-existing `ModuleLoadError`s were already handled.
2. flyte._sentry._is_user_error — classify any RuntimeUserError
subclass as a user error. Previously hard-coded to
(DeploymentError, ImageBuildError, InitializationError), missing
the other ~20 RuntimeUserError subclasses (ModuleLoadError,
OOMError, TaskTimeoutError, RuntimeDataValidationError,
CodeBundleError, RemoteTaskNotFoundError, etc.). Filtering on
the parent class is the right primitive — these errors are
intentionally raised as user-facing messages, not crash reports.
Closes
All match the same module_loader → <frozen importlib._bootstrap> →
user-module shape; this PR filters them out at the Sentry boundary:
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3T (fold_to_ascii)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3R (langchain_community)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3Q (requests)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3P (google.oauth2)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3N (boto3)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3M (common)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3K (common)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3J (tqdm)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3H (cloudpathlib)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3E (flytelib.manifest)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3D (KeyError 'GCP_ADR' from user os.environ)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3B (TypeError create_task_environment() missing positional arg)
• fixes https://github.com/flyteorg/flyte-sdk/issues/FLYTE-SDK-3C (NameError gcp_adr undefined)
Test plan
• New tests in `tests/flyte/utils/test_module_loader.py`:
• Single-file ModuleNotFoundError is wrapped in ModuleLoadError
with the original module name preserved.
• Directory walk records `ModuleNotFoundError`s in failed_paths
rather than crashing.
• Same wrapping applies to SyntaxError / NameError /
AttributeError / TypeError / ValueError on the single-file path.
• New tests in `tests/flyte/test_sentry.py`:
• ModuleLoadError (a RuntimeUserError) is filtered.
• Generic RuntimeUserError subclass (OOMError) is filtered.
• Wrapped ModuleLoadError via __cause__ is filtered.
• All 26 affected tests pass.
• make fmt clean.
• Commit signed (-s).
🤖 Generated with Claude Code
flyteorg/flyte-sdkacoustic-carpenter-78188
05/22/2026, 8:27 PM