mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Redesign Python exception hierarchy (#4082)
* [BREAKING] Redesign Python exception hierarchy Replace the flat ServiceException family with domain-scoped branches: - AgentException (with InvalidAuth, InvalidRequest, InvalidResponse, ContentFilter) - ChatClientException (same consistent suberrors) - IntegrationException (same + InitializationError) - WorkflowException (Runner, Convergence, Checkpoint, Validation, Action, Declarative) - ContentError (AdditionItemMismatch) - ToolException / ToolExecutionException (unchanged) - MiddlewareException / MiddlewareTermination (unchanged) Key changes: - All Service* exceptions removed (ServiceException, ServiceInitializationError, etc.) - AgentExecutionException split into AgentInvalidRequest/ResponseException - AgentInvocationError removed, split into AgentInvalidRequest/ResponseException - Workflow exceptions moved from _workflows/_exceptions.py into main exceptions.py - _workflows/__init__.py emptied; main __init__.py imports directly from submodules - Purview exceptions re-parented under IntegrationException hierarchy - Init validation errors use built-in ValueError/TypeError instead of custom exceptions - CODING_STANDARD.md updated with hierarchy design and rationale Fixes microsoft/agent-framework#3410 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Clarify ToolException vs ToolExecutionException docstrings ToolException: base class for all tool-related exceptions (preconditions, connection/init failures). ToolExecutionException: runtime call failures (tool call failed, reconnect failed, MCP errors). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix remaining stale imports from agent_framework._workflows - azurefunctions: _context.py, _app.py, _serialization.py, test_func_utils.py used 'from agent_framework._workflows import X' which broke after emptying _workflows/__init__.py; changed to direct submodule imports - azure-ai-search: test still referenced ServiceInitializationError; updated to ValueError to match production code Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
7f606a2e3a
commit
5ee06853a1
@@ -20,10 +20,10 @@ Integration with Microsoft Purview for data governance and policy enforcement.
|
||||
|
||||
### Exceptions
|
||||
|
||||
- **`PurviewAuthenticationError`** - Authentication failures
|
||||
- **`PurviewRateLimitError`** - Rate limit exceeded
|
||||
- **`PurviewRequestError`** / **`PurviewServiceError`** - Request/service errors
|
||||
- **`PurviewPaymentRequiredError`** - Payment required
|
||||
- **`PurviewAuthenticationError`** - Authentication failures (inherits from `IntegrationInvalidAuthException`)
|
||||
- **`PurviewRateLimitError`** - Rate limit exceeded (inherits from `IntegrationException` via `PurviewServiceError`)
|
||||
- **`PurviewRequestError`** / **`PurviewServiceError`** - Request/service errors (inherit from `IntegrationException`)
|
||||
- **`PurviewPaymentRequiredError`** - Payment required (inherits from `IntegrationException` via `PurviewServiceError`)
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Purview specific exceptions (minimal error shaping)."""
|
||||
"""Purview specific exceptions mapped to the Integration exception hierarchy."""
|
||||
|
||||
from agent_framework.exceptions import ServiceResponseException
|
||||
from agent_framework.exceptions import IntegrationException, IntegrationInvalidAuthException
|
||||
|
||||
__all__ = [
|
||||
"PurviewAuthenticationError",
|
||||
@@ -12,11 +12,11 @@ __all__ = [
|
||||
]
|
||||
|
||||
|
||||
class PurviewServiceError(ServiceResponseException):
|
||||
class PurviewServiceError(IntegrationException):
|
||||
"""Base exception for Purview errors."""
|
||||
|
||||
|
||||
class PurviewAuthenticationError(PurviewServiceError):
|
||||
class PurviewAuthenticationError(IntegrationInvalidAuthException):
|
||||
"""Authentication / authorization failure (401/403)."""
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
"""Tests for Purview exceptions."""
|
||||
|
||||
from agent_framework.exceptions import IntegrationException, IntegrationInvalidAuthException
|
||||
|
||||
from agent_framework_purview import (
|
||||
PurviewAuthenticationError,
|
||||
PurviewPaymentRequiredError,
|
||||
@@ -18,28 +20,28 @@ class TestPurviewExceptions:
|
||||
"""Test PurviewServiceError base exception."""
|
||||
error = PurviewServiceError("Service error occurred")
|
||||
assert str(error) == "Service error occurred"
|
||||
assert isinstance(error, Exception)
|
||||
assert isinstance(error, IntegrationException)
|
||||
|
||||
def test_purview_authentication_error(self) -> None:
|
||||
"""Test PurviewAuthenticationError exception."""
|
||||
error = PurviewAuthenticationError("Authentication failed")
|
||||
assert str(error) == "Authentication failed"
|
||||
assert isinstance(error, PurviewServiceError)
|
||||
assert isinstance(error, IntegrationInvalidAuthException)
|
||||
|
||||
def test_purview_payment_required_error(self) -> None:
|
||||
"""Test PurviewPaymentRequiredError exception."""
|
||||
error = PurviewPaymentRequiredError("Payment required")
|
||||
assert str(error) == "Payment required"
|
||||
assert isinstance(error, PurviewServiceError)
|
||||
assert isinstance(error, IntegrationException)
|
||||
|
||||
def test_purview_rate_limit_error(self) -> None:
|
||||
"""Test PurviewRateLimitError exception."""
|
||||
error = PurviewRateLimitError("Rate limit exceeded")
|
||||
assert str(error) == "Rate limit exceeded"
|
||||
assert isinstance(error, PurviewServiceError)
|
||||
assert isinstance(error, IntegrationException)
|
||||
|
||||
def test_purview_request_error(self) -> None:
|
||||
"""Test PurviewRequestError exception."""
|
||||
error = PurviewRequestError("Request failed")
|
||||
assert str(error) == "Request failed"
|
||||
assert isinstance(error, PurviewServiceError)
|
||||
assert isinstance(error, IntegrationException)
|
||||
|
||||
Reference in New Issue
Block a user