Skip to content

fix: replace bare except: with except Exception: in sagemaker-train#5721

Open
harshadkhetpal wants to merge 3 commits intoaws:masterfrom
harshadkhetpal:fix/replace-bare-except-with-exception-2026-04-07
Open

fix: replace bare except: with except Exception: in sagemaker-train#5721
harshadkhetpal wants to merge 3 commits intoaws:masterfrom
harshadkhetpal:fix/replace-bare-except-with-exception-2026-04-07

Conversation

@harshadkhetpal
Copy link
Copy Markdown

Summary

Replace bare except: clauses with except Exception: in three files under sagemaker-train/:

  • sagemaker-train/src/sagemaker/train/evaluate/execution.py (2 occurrences)
  • sagemaker-train/src/sagemaker/train/common_utils/finetune_utils.py (1 occurrence)
  • sagemaker-train/src/sagemaker/train/common_utils/show_results_utils.py (2 occurrences)

Why

Bare except: catches all exceptions including SystemExit, KeyboardInterrupt, and GeneratorExit, which can mask critical errors and make debugging harder. PEP 8 recommends catching Exception instead when the intent is to catch program errors.

In all five cases here, the bare except: is used for optional import detection (IPython/Jupyter) or non-critical formatting, where catching Exception is the correct behavior.

Testing

This is a minimal, safe change — except Exception: is strictly a subset of bare except: (excludes only BaseException subclasses like KeyboardInterrupt and SystemExit). No functional behavior changes for normal error handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant