{"record":{"id":"a4a5a6bb352ab29d","repo":"CherryHQ/cherry-studio","slug":"failed-to-generate-image-error-message","errorCode":null,"errorMessage":"Failed to generate image: ${error.message}","messagePattern":"Failed to generate image: (.+?)","errorType":"exception","errorClass":"ImageGenerationError","httpStatus":null,"severity":"error","filePath":"packages/aiCore/src/core/runtime/executor.ts","lineNumber":203,"sourceCode":"                      providerId: this.config.providerId,\n                      modelId: activeModel.modelId,\n                      imageCount: result.images.length,\n                      ...(result.usage ? { usage: result.usage } : {}),\n                      metrics: { timeCompletionMs: Math.max(0, Math.round(performance.now() - startedAt)) },\n                      completedAt: Date.now()\n                    })\n                    return result\n                  }\n                }\n              })\n            : resolvedModel\n          return _generateImage({ ...transformedParams, model: observedModel })\n        }\n      )\n    } catch (error) {\n      if (error instanceof Error) {\n        const modelId = typeof params.model === 'string' ? params.model : params.model.modelId\n        throw new ImageGenerationError(\n          `Failed to generate image: ${error.message}`,\n          this.config.providerId,\n          modelId,\n          error\n        )\n      }\n      throw error\n    }\n  }\n\n  /**\n   * 批量嵌入文本\n   */\n  async embedMany(params: EmbedManyParams): Promise<EmbedManyResult> {\n    const { model: modelOrId, onProviderCall, ...options } = params\n\n    // 解析 embedding 模型\n    const embeddingModel =","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/packages/aiCore/src/core/runtime/executor.ts#L185-L221","documentation":"RuntimeExecutor.generateImage wraps its entire body in try/catch; any Error thrown during the plugin pipeline or _generateImage is rethrown as ImageGenerationError with providerId, modelId, and the original cause. Non-Error throws are rethrown as-is. This gives callers a single typed error for image failures.","triggerScenarios":"Any failure inside generateImage: model resolution error, provider HTTP error, invalid image params, network failure, rate limit, or content-policy rejection from the image API.","commonSituations":"Wrong/unsupported image model id; provider doesn't support image generation; malformed prompt/size param; API key invalid; rate limited; the model id passed as a string doesn't exist in the provider's imageModel registry.","solutions":["Read err.cause and err.modelId/err.providerId on the ImageGenerationError to find the real failure.","Verify the model id is a valid image model for the provider and that supportsImageGeneration is true.","Validate prompt/size/aspectRatio params against the provider's image API before calling."],"exampleFix":"// before\nawait executor.generateImage({ model: 'dall-e-3', prompt: '...' }) // throws opaque ImageGenerationError\n// after — inspect cause\ntry {\n  await executor.generateImage({ model: 'dall-e-3', prompt: '...' })\n} catch (e) {\n  if (e instanceof ImageGenerationError) console.error(e.message, e.cause, e.modelId)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"import { ImageGenerationError } from '@cherrystudio/ai-core/runtime'\nfunction isImageGenerationError(e: unknown): e is ImageGenerationError {\n  return e instanceof ImageGenerationError\n}","tryCatchPattern":"try {\n  await executor.generateImage({ model, prompt })\n} catch (e) {\n  if (e instanceof ImageGenerationError) {\n    console.error('image gen failed', e.providerId, e.modelId, e.cause)\n  }\n}","preventionTips":["Validate image params (size, aspectRatio, prompt) against the provider spec before calling.","Confirm the model id is a valid image model and supportsImageGeneration is true.","Always read ImageGenerationError.cause for the actionable message."],"tags":["image-generation","error-wrapping","runtime"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}