linshenkx/prompt-optimizer · warning · ImageError
UNSUPPORTED_TEST_TYPE
UNSUPPORTED_TEST_TYPE
Error message
UNSUPPORTED_TEST_TYPE
What it means
The SiliconFlow adapter only implements test image requests for 'text2image' and 'image2image'. getTestImageRequest returns a request for those two types and throws UNSUPPORTED_TEST_TYPE for anything else.
Source
Thrown at packages/core/src/services/image/adapters/siliconflow.ts:265
if (testType === 'text2image') {
return {
prompt: 'a flower',
count: 1
}
}
if (testType === 'image2image') {
return {
prompt: 'make it red',
count: 1,
inputImage: {
b64: AbstractImageProviderAdapter.TEST_IMAGE_BASE64.split(',')[1], // 去掉data:前缀
mimeType: 'image/png'
}
}
}
throw new ImageError(IMAGE_ERROR_CODES.UNSUPPORTED_TEST_TYPE, undefined, { testType })
}
protected async doGenerate(request: ImageRequest, config: ImageModelConfig): Promise<ImageResult> {
// 构建请求体,隐藏多图相关参数并固定为单图
const mergedParams: Record<string, any> = {
// 使用默认参数和覆盖参数
...config.paramOverrides,
...request.paramOverrides
}
delete mergedParams.n
delete mergedParams.batch_size
const response = await this.apiCall(config, '/images/generations', {
method: 'POST',
headers: {
'Authorization': `Bearer ${config.connectionConfig?.apiKey}`,
'Content-Type': 'application/json'
},View on GitHub (pinned to 3e677b1d9f)
Solutions
- Restrict the caller to the two supported literals: 'text2image' | 'image2image'
- Add a check before calling: if (testType !== 'text2image' && testType !== 'image2image') return
- If a new test type is genuinely needed, implement its branch in getTestImageRequest
Example fix
// before
const req = adapter.getTestImageRequest(userSelectedType as any)
// after
const SUPPORTED = ['text2image', 'image2image'] as const
if (!SUPPORTED.includes(testType)) {
throw new Error(`Unsupported test type: ${testType}`)
}
const req = adapter.getTestImageRequest(testType) Defensive patterns
Strategy: type-guard
Validate before calling
const SUPPORTED_TEST_TYPES = ['text2image', 'image2image'] as const
if (!SUPPORTED_TEST_TYPES.includes(testType)) {
throw new Error(`Test type must be one of ${SUPPORTED_TEST_TYPES.join(', ')}`)
} Type guard
function isSupportedTestType(t: unknown): t is 'text2image' | 'image2image' {
return t === 'text2image' || t === 'image2image'
} Try / catch
try {
const req = adapter.getTestImageRequest(testType)
} catch (e) {
if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.UNSUPPORTED_TEST_TYPE) {
hideTestOption(testType); return
}
throw e
} Prevention
- Type the testType parameter as the literal union, not string
- Derive UI test options from the same constant list the adapter supports
When it happens
Trigger: Calling getTestImageRequest with a testType other than the literal 'text2image' or 'image2image' — e.g. 'video', 'inpaint', a typo like 'text-to-image', or an unvalidated string from user input.
Common situations: New test type added to UI without adapter support; string constants drifted between caller and adapter; dynamically-built testType from a config enum that includes more variants.
Related errors
- UNSUPPORTED_TEST_TYPE
- UNSUPPORTED_TEST_TYPE
- UNSUPPORTED_TEST_TYPE
- API_KEY_REQUIRED
- CONTEXT_ERROR_CODES.STORAGE_ERROR
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/7bb5c2c8df2e952a.
Report an issue: GitHub.