Skip to content

fix: wrap any user-module import exception as ModuleLoadError#1168

Open
EngHabu wants to merge 1 commit into
mainfrom
claude/sentry-fix-module-exception
Open

fix: wrap any user-module import exception as ModuleLoadError#1168
EngHabu wants to merge 1 commit into
mainfrom
claude/sentry-fix-module-exception

Conversation

@EngHabu

@EngHabu EngHabu commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Problem

User modules can raise arbitrary third-party exceptions at import time that don't inherit from RuntimeError / ImportError / etc. The clearest example: google.api_core.exceptions.RetryError (parent: Exception) is raised when a user's module-top-level code calls Google Secret Manager and gcloud credentials have expired. The SDK's import loop only catches a narrow tuple — (ImportError, SyntaxError, NameError, AttributeError, TypeError, ValueError, KeyError, RuntimeError) — so anything else escapes and lands in Sentry as if it were an SDK bug.

PRs #1094 / #1134 / #1146 widened that tuple incrementally. Time to finish the job: anything raised inside importlib.import_module(<user-module>) is, by definition, an error in the user's code or its third-party imports.

Fix

Widen both except clauses in src/flyte/_utils/module_loader.py (file-path branch and directory branch) from the explicit tuple to plain except Exception. Wrap as flyte.errors.ModuleLoadError (a RuntimeUserError already filtered by flyte/_sentry.py:_is_user_error) so deploy surfaces an actionable error and Sentry stops receiving user import-time crashes.

Closes

  • FLYTE-SDK-39google.api_core.exceptions.RetryError: Timeout of 60.0s exceeded raised from the user's gsm_secrets.set_secrets_as_dict_gcp_flyte during user-module import (expired gcloud creds — gcloud auth application-default login).

fixes FLYTE-SDK-39

Tests

  • Added a test that a user module raising a non-RuntimeError Exception subclass at import time is captured as a load failure (or re-raised as ModuleLoadError for the file-path branch).

@EngHabu EngHabu added the sentry-fix Fix for an issue surfaced by Sentry label Jun 5, 2026
@EngHabu EngHabu force-pushed the claude/sentry-fix-module-exception branch 4 times, most recently from 548b44a to 9e8bdc4 Compare June 11, 2026 16:11

@EngHabu EngHabu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.. not sure how you feel about the blanket except Exception

@EngHabu EngHabu requested review from AdilFayyaz and pingsutw June 11, 2026 19:38
@EngHabu EngHabu enabled auto-merge (squash) June 11, 2026 19:38
@EngHabu EngHabu force-pushed the claude/sentry-fix-module-exception branch from 9e8bdc4 to 6798c29 Compare June 12, 2026 16:09
Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
@EngHabu EngHabu force-pushed the claude/sentry-fix-module-exception branch from 6798c29 to 549cc94 Compare June 13, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sentry-fix Fix for an issue surfaced by Sentry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant