mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: fix: prevent inner_exception from being lost in AgentFrameworkException (#5167)
* fix: prevent inner_exception from being lost in AgentFrameworkException The __init__ method unconditionally called super().__init__() after the conditional call with inner_exception, effectively overwriting the exception args and losing the inner_exception reference. Add else branch so super().__init__() is only called once with the correct arguments. Fixes #5155 Signed-off-by: bahtya <bahtyar153@qq.com> * test: add explicit tests for AgentFrameworkException inner_exception handling - test_exception_with_inner_exception: verifies args include inner exception - test_exception_without_inner_exception: verifies args only contain message - test_exception_inner_exception_none_explicit: verifies explicit None Covers both branches of the if/else in __init__. * fix: export AgentFrameworkException from package Bahtya --------- Signed-off-by: bahtya <bahtyar153@qq.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
56fb634f0e
commit
dad3652f46
@@ -0,0 +1,29 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
"""Tests for AgentFrameworkException inner_exception handling."""
|
||||
|
||||
import pytest
|
||||
|
||||
from agent_framework import AgentFrameworkException
|
||||
|
||||
|
||||
def test_exception_with_inner_exception():
|
||||
"""When inner_exception is provided, it should be set as the second arg."""
|
||||
inner = ValueError("inner error")
|
||||
exc = AgentFrameworkException("test message", inner_exception=inner)
|
||||
assert exc.args[0] == "test message"
|
||||
assert exc.args[1] is inner
|
||||
|
||||
|
||||
def test_exception_without_inner_exception():
|
||||
"""When inner_exception is None, args should only contain the message."""
|
||||
exc = AgentFrameworkException("test message")
|
||||
assert exc.args == ("test message",)
|
||||
assert len(exc.args) == 1
|
||||
|
||||
|
||||
def test_exception_inner_exception_none_explicit():
|
||||
"""When inner_exception is explicitly None, args should only contain the message."""
|
||||
exc = AgentFrameworkException("test message", inner_exception=None)
|
||||
assert exc.args == ("test message",)
|
||||
assert len(exc.args) == 1
|
||||
Reference in New Issue
Block a user