Skip to content

Commit 5e795d9

Browse files
authored
refactor: log more error context for tool calling (#7)
1 parent 21a0258 commit 5e795d9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Server/JsonRpcHandler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public function process(string $message): ?string
4343

4444
try {
4545
$message = $this->messageFactory->create($message);
46-
} catch (\JsonException $exception) {
47-
$this->logger->warning('Failed to decode json message', ['exception' => $exception]);
46+
} catch (\JsonException $e) {
47+
$this->logger->warning('Failed to decode json message', ['exception' => $e]);
4848

49-
return $this->encodeResponse(Error::parseError($exception->getMessage()));
50-
} catch (\InvalidArgumentException $exception) {
51-
$this->logger->warning('Failed to create message', ['exception' => $exception]);
49+
return $this->encodeResponse(Error::parseError($e->getMessage()));
50+
} catch (\InvalidArgumentException $e) {
51+
$this->logger->warning('Failed to create message', ['exception' => $e]);
5252

53-
return $this->encodeResponse(Error::invalidRequest(0, $exception->getMessage()));
53+
return $this->encodeResponse(Error::invalidRequest(0, $e->getMessage()));
5454
}
5555

5656
$this->logger->info('Decoded incoming message', ['message' => $message]);
@@ -60,10 +60,10 @@ public function process(string $message): ?string
6060
? $this->handleNotification($message) : $this->encodeResponse($this->handleRequest($message));
6161
} catch (\DomainException) {
6262
return null;
63-
} catch (\InvalidArgumentException $exception) {
64-
$this->logger->warning('Failed to create response', ['exception' => $exception]);
63+
} catch (\InvalidArgumentException $e) {
64+
$this->logger->warning(sprintf('Failed to create response: %s', $e->getMessage()), ['exception' => $e]);
6565

66-
return $this->encodeResponse(Error::methodNotFound($message->id ?? 0, $exception->getMessage()));
66+
return $this->encodeResponse(Error::methodNotFound($message->id ?? 0, $e->getMessage()));
6767
}
6868
}
6969

0 commit comments

Comments
 (0)