Skip to content

Commit 2e43da3

Browse files
committed
Fix exceptions to use sprintf for string formatting
Replace string concatenation and interpolation with sprintf in all exception messages for consistency and better formatting.
1 parent 5e12f02 commit 2e43da3

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

src/mcp-sdk/src/Server/RequestHandler/PromptGetHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function createResponse(Request $message): Response|Error
5858
],
5959
],
6060
// TODO better exception
61-
default => throw new InvalidArgumentException('Unsupported PromptGet result type: '.$resultMessage->type),
61+
default => throw new InvalidArgumentException(\sprintf('Unsupported PromptGet result type: %s', $resultMessage->type)),
6262
};
6363

6464
$messages[] = [

src/mcp-sdk/src/Server/RequestHandler/ToolCallHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function createResponse(Request $message): Response|Error
5656
],
5757
],
5858
// TODO better exception
59-
default => throw new InvalidArgumentException('Unsupported tool result type: '.$result->type),
59+
default => throw new InvalidArgumentException(\sprintf('Unsupported tool result type: %s', $result->type)),
6060
};
6161

6262
return new Response($message->id, [

src/platform/src/Bridge/HuggingFace/ResultConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public function convert(RawResultInterface|RawHttpResult $result, array $options
6565
default => $content['error'],
6666
};
6767

68-
throw new InvalidArgumentException(\sprintf('API Client Error (%d): ', $httpResponse->getStatusCode()).$message);
68+
throw new InvalidArgumentException(\sprintf('API Client Error (%d): %s', $httpResponse->getStatusCode(), $message));
6969
}
7070

7171
if (200 !== $httpResponse->getStatusCode()) {
72-
throw new RuntimeException('Unhandled response code: '.$httpResponse->getStatusCode());
72+
throw new RuntimeException(\sprintf('Unhandled response code: %d', $httpResponse->getStatusCode()));
7373
}
7474

7575
$task = $options['task'] ?? null;

src/platform/src/Bridge/Mistral/Embeddings/ResultConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function convert(RawResultInterface|RawHttpResult $result, array $options
3535
$httpResponse = $result->getObject();
3636

3737
if (200 !== $httpResponse->getStatusCode()) {
38-
throw new RuntimeException(\sprintf('Unexpected response code %d: ', $httpResponse->getStatusCode()).$httpResponse->getContent(false));
38+
throw new RuntimeException(\sprintf('Unexpected response code %d: %s', $httpResponse->getStatusCode(), $httpResponse->getContent(false)));
3939
}
4040

4141
$data = $result->getData();

src/platform/src/Bridge/Mistral/Llm/ResultConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function convert(RawResultInterface|RawHttpResult $result, array $options
5050
}
5151

5252
if (200 !== $code = $httpResponse->getStatusCode()) {
53-
throw new RuntimeException(\sprintf('Unexpected response code %d: ', $code).$httpResponse->getContent(false));
53+
throw new RuntimeException(\sprintf('Unexpected response code %d: %s', $code, $httpResponse->getContent(false)));
5454
}
5555

5656
$data = $result->getData();

src/platform/src/Vector/Vector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public function __construct(
2626
private ?int $dimensions = null,
2727
) {
2828
if (null !== $dimensions && $dimensions !== \count($data)) {
29-
throw new InvalidArgumentException('Vector must have '.$dimensions.' dimensions');
29+
throw new InvalidArgumentException(\sprintf('Vector must have %d dimensions', $dimensions));
3030
}
3131

3232
if ([] === $data) {
3333
throw new InvalidArgumentException('Vector must have at least one dimension.');
3434
}
3535

3636
if (\is_int($dimensions) && \count($data) !== $dimensions) {
37-
throw new InvalidArgumentException('Vector must have '.$dimensions.' dimensions');
37+
throw new InvalidArgumentException(\sprintf('Vector must have %d dimensions', $dimensions));
3838
}
3939

4040
if (null === $this->dimensions) {

src/store/src/Bridge/ClickHouse/Store.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private function insertBatch(array $rows): void
173173
if (200 !== $response->getStatusCode()) {
174174
$content = $response->getContent(false);
175175

176-
throw new RuntimeException("Could not insert data into ClickHouse. Http status code: {$response->getStatusCode()}. Response: {$content}.");
176+
throw new RuntimeException(\sprintf('Could not insert data into ClickHouse. Http status code: %d. Response: %s.', $response->getStatusCode(), $content));
177177
}
178178
}
179179

0 commit comments

Comments
 (0)