Activate rules to prevent exception handling anti-patterns#11282
Activate rules to prevent exception handling anti-patterns#11282lukasmasuch merged 4 commits intodevelopfrom
Conversation
✅ PR preview is ready!
|
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR activates additional linting rules aimed at preventing exception handling anti‐patterns throughout the codebase. Key changes include switching from _LOGGER.error to _LOGGER.exception for improved logging of exceptions, standardizing exception types (e.g. using RuntimeError or TypeError), and updating linter configurations in .ruff.toml.
- Updated logging calls across multiple server and connection modules.
- Revised exception raises to use more specific exception types.
- Refined linter ignore settings in .ruff.toml to enforce the new TRY lint rules.
Reviewed Changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/streamlit/web/server/media_file_handler.py | Changed logging from _LOGGER.error to _LOGGER.exception for missing file errors. |
| lib/streamlit/web/server/component_request_handler.py | Updated exception logging and error sanitization during file read errors. |
| lib/streamlit/web/server/browser_websocket_handler.py | Replaced RuntimeError with TypeError for incorrect message payload types. |
| lib/streamlit/web/bootstrap.py | Switched error logging to _LOGGER.exception when loading secrets. |
| lib/streamlit/runtime/scriptrunner/script_runner.py | Updated exception type from Exception to RuntimeError and simplified re-raising exceptions. |
| lib/streamlit/runtime/caching/storage/cache_storage_protocol.py | Renamed InvalidCacheStorageContext to InvalidCacheStorageContextError. |
| lib/streamlit/connections/snowflake_connection.py | Adjusted exception handling for Snowflake connection errors. |
| .ruff.toml | Added new TRY lint rules and updated per-file ignore patterns to accommodate them. |
Comments suppressed due to low confidence (3)
lib/streamlit/web/server/media_file_handler.py:90
- Ensure that using _LOGGER.exception here provides sufficient context for troubleshooting without exposing sensitive internal details. Verify that logging the full stack trace is appropriate for the production environment.
_LOGGER.exception("MediaFileHandler: Missing file %s", absolute_path)
lib/streamlit/web/server/browser_websocket_handler.py:215
- Ensure that replacing RuntimeError with TypeError accurately reflects the type-checking failure and that the exception message clearly indicates that string messages are not supported.
raise TypeError( # noqa: TRY301
.ruff.toml:122
- [nitpick] Review and update the .ruff.toml configuration to ensure that the new TRY lint rules integrate well with existing exception logging patterns and do not cause unintended false positives.
"TRY003", # Checks for exception messages that are not defined in the exception class itself.
📉 Python coverage change detectedThe Python unit test coverage has decreased by 0.0330%
💡 Consider adding more unit tests to maintain or improve coverage. Coverage by files
|
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
Describe your changes
Activates linting rules to prevent exception handling anti-patterns in Python:
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.