fix(clI): print the errror message alone instead of JSON in the CLI (#2580)

Currently we print the JSON structure even when used in the CLI.
This commit is contained in:
Dominik Inführ
2026-08-16 09:36:08 +00:00
committed by GitHub
parent 5d0283969c
commit fce756ad19
2 changed files with 21 additions and 1 deletions
+9
View File
@@ -224,6 +224,15 @@ export async function handleResponse(
format: 'json' | 'md',
): Promise<string> {
if (response.isError) {
if (format === 'md') {
const chunks = [];
for (const content of response.content) {
if (content.type === 'text') {
chunks.push(content.text);
}
}
return chunks.join(' ');
}
return JSON.stringify(response.content);
}
const chunks = [];
+12 -1
View File
@@ -126,13 +126,24 @@ describe('daemon client', () => {
);
});
it('handles error response when isError is true', async () => {
it('handles error response when isError is true with md format', async () => {
const errorResponse = {
isError: true,
content: [{type: 'text' as const, text: 'Something went wrong'}],
};
assert.strictEqual(
await handleResponse(errorResponse, 'md'),
'Something went wrong',
);
});
it('handles error response when isError is true with json format', async () => {
const errorResponse = {
isError: true,
content: [{type: 'text' as const, text: 'Something went wrong'}],
};
assert.strictEqual(
await handleResponse(errorResponse, 'json'),
JSON.stringify(errorResponse.content),
);
});