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:
parent
bfc4728792
commit
73414d65f6
1 changed files with 88 additions and 27 deletions
|
|
@ -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,
|
||||
],
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue