Add PSR-3 compliant exception context when logging exceptions (#300)

* Add PSR-3 exception context to caught error logs

* Apply review feedback
This commit is contained in:
Sven Münnich 2026-05-12 23:20:42 +02:00 • committed by GitHub
commit 73414d65f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -166,16 +166,18 @@ class CallToolHandlerTest extends TestCase
public function testHandleToolNotFoundExceptionReturnsError(): void
{
$request = $this->createCallToolRequest('nonexistent_tool', ['param' => 'value']);
$exception = new ToolNotFoundException('nonexistent_tool');
$this->registry
->expects($this->once())
->method('getTool')
->with('nonexistent_tool')
->willThrowException(new ToolNotFoundException('nonexistent_tool'));
->willThrowException($exception);
$this->logger
->expects($this->once())
->method('error');
->method('error')
->with('Tool not found', ['name' => 'nonexistent_tool', 'exception' => $exception]);
$response = $this->handler->handle($request, $this->session);
@ -206,7 +208,15 @@ class CallToolHandlerTest extends TestCase
$this->logger
->expects($this->once())
->method('error');
->method('error')
->with(
'Error while executing tool "failing_tool": "Tool execution failed".',
[
'tool' => 'failing_tool',
'arguments' => ['param' => 'value', '_session' => $this->session, '_request' => $request],
'exception' => $exception,
],
);
$response = $this->handler->handle($request, $this->session);
@ -288,6 +298,7 @@ class CallToolHandlerTest extends TestCase
[
'tool' => 'test_tool',
'arguments' => ['key1' => 'value1', 'key2' => 42, '_session' => $this->session, '_request' => $request],
'exception' => $exception,
],
);