-
Notifications
You must be signed in to change notification settings - Fork 589
Replace Exception with specific error types #5755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replaces generic Exception raises with more specific error types such as RuntimeError, ValueError, NotImplementedError, ImportError, and custom exceptions across multiple modules. This improves error handling clarity and aligns with Python best practices for exception usage.
Deploying flet-docs with
|
| Latest commit: |
2e1d290
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ce8b6cc3.flet-docs.pages.dev |
| Branch Preview URL: | https://v1-flet-exceptions.flet-docs.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've reviewed this pull request using the Sourcery rules engine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR standardizes exception handling by replacing generic Exception with more specific exception types throughout the Flet Python SDK. The changes improve error handling semantics by using appropriate built-in exceptions (RuntimeError, ValueError, ImportError, NotImplementedError) and custom Flet exceptions where applicable.
Key changes:
- Replace generic
Exceptionwith specific exception types for better error semantics - Use
HTTPExceptionwith proper status codes in FastAPI upload handler - Remove deprecated
clean()method from control.py - Minor code formatting improvements (import ordering, removing unnecessary encoding parameters)
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| platform_utils.py | Changed to use FletUnsupportedPlatformException for platform/architecture errors; removed redundant "r" mode parameter |
| files.py | Changed to RuntimeError for path traversal security error |
| flet_test_app.py | Changed to RuntimeError for missing golden image |
| security/init.py | Changed to ImportError for missing cryptography dependency |
| session.py | Changed to RuntimeError for method invocation errors |
| pyodide_connection.py | Changed to RuntimeError for unknown message protocol errors |
| protocol.py | Changed to RuntimeError for serialization errors |
| flet_socket_server.py | Changed to RuntimeError for unknown message protocol errors |
| connection.py | Changed to RuntimeError for uninitialized component errors |
| page.py | Changed to RuntimeError for destroyed session access |
| object_patch.py | Changed to ObjectPatchException for parent validation and RuntimeError for frozen control errors |
| control_event.py | Changed to RuntimeError for event field resolution errors |
| control.py | Removed deprecated clean() method |
| base_page.py | Changed to RuntimeError for duplicate dialog errors |
| base_control.py | Changed to ValueError for decorator validation and RuntimeError for frozen control updates |
| oauth_provider.py | Changed to NotImplementedError for abstract method |
| authorization_service.py | Changed to ValueError for missing required configuration |
| authentication.md | Changed to RuntimeError in documentation example |
| uploads.py | Changed to RuntimeError for missing secret key; removed unnecessary encoding parameter |
| flet_upload.py | Changed to use HTTPException with proper status codes; improved error handling and validation |
| flet_static_files.py | Changed to RuntimeError for missing web root; reordered imports |
| flet_app_manager.py | Changed to RuntimeError for session errors; reordered imports |
| flet_app.py | Changed to RuntimeError for unknown message protocol errors |
| project_dependencies.py | Changed to ValueError for unsupported dependency specification; removed blank lines |
| android_sdk.py | Changed to RuntimeError for Android SDK errors; reordered imports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replaces generic Exception raises with more specific error types such as RuntimeError, ValueError, NotImplementedError, ImportError, and custom exceptions across multiple modules. This improves error handling clarity and aligns with Python best practices for exception usage.
Closes #5428
Summary by Sourcery
Improve error handling by replacing generic Exception raises with specific exception types across multiple modules, enhancing clarity and aligning with Python best practices.
Enhancements: