fix: replace bare `except:` with `except Exception:` in sagemaker-train by harshadkhetpal · Pull Request #5721 · aws/sagemaker-python-sdk

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.