Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/packages/core/agent_framework/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def __init__(
logger.log(log_level, message, exc_info=inner_exception)
if inner_exception:
super().__init__(message, inner_exception, *args) # type: ignore
super().__init__(message, *args) # type: ignore
else:
super().__init__(message, *args) # type: ignore


# region Agent Exceptions
Expand Down
29 changes: 29 additions & 0 deletions python/packages/core/tests/core/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -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