Skip to content

Conversation

@FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Oct 28, 2025

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:

  • Use HTTPException with detailed status codes in FastAPI endpoints for upload and app management errors
  • Replace generic Exception raises with precise built-in errors (RuntimeError, ValueError, NotImplementedError, ImportError) in core modules, messaging, controls, CLI utilities, dependency formatting, security, and file utilities
  • Introduce custom exceptions (ObjectPatchException, FletUnsupportedPlatformException) for domain-specific error scenarios in object patching and platform detection

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.
@cloudflare-workers-and-pages
Copy link

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

@FeodorFitsner FeodorFitsner marked this pull request as ready for review October 31, 2025 14:24
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

Copy link
Contributor

Copilot AI left a 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 Exception with specific exception types for better error semantics
  • Use HTTPException with 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.

@FeodorFitsner FeodorFitsner merged commit fc43cf9 into main Oct 31, 2025
36 of 52 checks passed
@FeodorFitsner FeodorFitsner deleted the v1-flet-exceptions branch October 31, 2025 16:15
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.

v1: Use custom Flet exceptions

3 participants