CherryHQ/cherry-studio · error · ImageGenerationError

Failed to generate image: ${error.message}

Error message

Failed to generate image: ${error.message}

What it means

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.

Source

Thrown at packages/aiCore/src/core/runtime/executor.ts:203

                      providerId: this.config.providerId,
                      modelId: activeModel.modelId,
                      imageCount: result.images.length,
                      ...(result.usage ? { usage: result.usage } : {}),
                      metrics: { timeCompletionMs: Math.max(0, Math.round(performance.now() - startedAt)) },
                      completedAt: Date.now()
                    })
                    return result
                  }
                }
              })
            : resolvedModel
          return _generateImage({ ...transformedParams, model: observedModel })
        }
      )
    } catch (error) {
      if (error instanceof Error) {
        const modelId = typeof params.model === 'string' ? params.model : params.model.modelId
        throw new ImageGenerationError(
          `Failed to generate image: ${error.message}`,
          this.config.providerId,
          modelId,
          error
        )
      }
      throw error
    }
  }

  /**
   * 批量嵌入文本
   */
  async embedMany(params: EmbedManyParams): Promise<EmbedManyResult> {
    const { model: modelOrId, onProviderCall, ...options } = params

    // 解析 embedding 模型
    const embeddingModel =

View on GitHub (pinned to 726446b54c)

Solutions

  1. Read err.cause and err.modelId/err.providerId on the ImageGenerationError to find the real failure.
  2. Verify the model id is a valid image model for the provider and that supportsImageGeneration is true.
  3. Validate prompt/size/aspectRatio params against the provider's image API before calling.

Example fix

// before
await executor.generateImage({ model: 'dall-e-3', prompt: '...' }) // throws opaque ImageGenerationError
// after — inspect cause
try {
  await executor.generateImage({ model: 'dall-e-3', prompt: '...' })
} catch (e) {
  if (e instanceof ImageGenerationError) console.error(e.message, e.cause, e.modelId)
}
Defensive patterns

Strategy: try-catch

Type guard

import { ImageGenerationError } from '@cherrystudio/ai-core/runtime'
function isImageGenerationError(e: unknown): e is ImageGenerationError {
  return e instanceof ImageGenerationError
}

Try / catch

try {
  await executor.generateImage({ model, prompt })
} catch (e) {
  if (e instanceof ImageGenerationError) {
    console.error('image gen failed', e.providerId, e.modelId, e.cause)
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/a4a5a6bb352ab29d. Report an issue: GitHub.