Skip to content

Replace bare except with except Exception in execution.py#5663

Open
harshadkhetpal wants to merge 1 commit intoaws:masterfrom
harshadkhetpal:fix/bare-except-execution-2026-03-23
Open

Replace bare except with except Exception in execution.py#5663
harshadkhetpal wants to merge 1 commit intoaws:masterfrom
harshadkhetpal:fix/bare-except-execution-2026-03-23

Conversation

@harshadkhetpal
Copy link

Summary

This PR replaces bare except: clauses with except Exception: in sagemaker-train/src/sagemaker/train/evaluate/execution.py.

Bare except: catches all exceptions including SystemExit, KeyboardInterrupt, and GeneratorExit, which are typically not intended to be caught. Using except Exception: is the recommended practice as it only catches regular exceptions while allowing system-level exceptions to propagate normally.

Changes

  • Line 907: except:except Exception: (IPython import fallback)
  • Line 961: except:except Exception: (datetime parsing fallback)

Testing

This is a safe behavioral improvement — except Exception: covers all the same cases these handlers intend to catch (ImportError, ValueError, etc.) without accidentally suppressing KeyboardInterrupt or SystemExit.

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