Skip to content

Commit 1a910fd

Browse files
committed
minor #333 Fix exceptions to use sprintf for string formatting (OskarStark)
This PR was merged into the main branch. Discussion ---------- Fix exceptions to use `sprintf` for string formatting | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | -- | License | MIT Replace string concatenation and interpolation with sprintf in all exception messages for consistency and better formatting. Commits ------- af0051f Fix exceptions to use sprintf for string formatting
2 parents 32d8103 + af0051f commit 1a910fd

File tree

8 files changed

+10
-10
lines changed

8 files changed

+10
-10
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

src/store/tests/Bridge/ClickHouse/StoreTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testAddThrowsExceptionOnHttpError()
127127
$store = new Store($httpClient, 'test_db', 'test_table');
128128

129129
$this->expectException(RuntimeException::class);
130-
$this->expectExceptionMessage('Could not insert data into ClickHouse. Http status code: 500. Response: Internal Server Error.');
130+
$this->expectExceptionMessage('Could not insert data into ClickHouse. Http status code: 500. Response: "Internal Server Error".');
131131

132132
$store->add($document);
133133
}

0 commit comments

Comments
 (0)