Replace Exception with specific error types#5755
Merged
FeodorFitsner merged 1 commit intomainfrom Oct 31, 2025
Merged
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 |
Contributor
There was a problem hiding this comment.
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.
ndonkoHenri
approved these changes
Oct 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: