mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 07:10:55 +00:00
fix(cli): extract duplicate error formatting and add tests for /btw command
Extract repeated error formatting into formatBtwError helper, remove
no-op marginTop={0}, and add comprehensive test coverage for all three
execution modes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fda065314f
commit
d285c4409a
3 changed files with 386 additions and 10 deletions
|
|
@ -15,6 +15,12 @@ import type { HistoryItemBtw } from '../types.js';
|
|||
import { t } from '../../i18n/index.js';
|
||||
import type { GeminiClient } from '@qwen-code/qwen-code-core';
|
||||
|
||||
function formatBtwError(error: unknown): string {
|
||||
return t('Failed to answer btw question: {{error}}', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to make the ephemeral generateContent call and extract the answer.
|
||||
* Uses a snapshot of the current conversation history as context.
|
||||
|
|
@ -114,9 +120,7 @@ export const btwCommand: SlashCommand = {
|
|||
} catch (error) {
|
||||
yield {
|
||||
messageType: 'error' as const,
|
||||
content: t('Failed to answer btw question: {{error}}', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
}),
|
||||
content: formatBtwError(error),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
@ -137,9 +141,7 @@ export const btwCommand: SlashCommand = {
|
|||
return {
|
||||
type: 'message',
|
||||
messageType: 'error',
|
||||
content: t('Failed to answer btw question: {{error}}', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
}),
|
||||
content: formatBtwError(error),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -189,9 +191,7 @@ export const btwCommand: SlashCommand = {
|
|||
ui.addItem(
|
||||
{
|
||||
type: MessageType.ERROR,
|
||||
text: t('Failed to answer btw question: {{error}}', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
}),
|
||||
text: formatBtwError(error),
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue