linshenkx/prompt-optimizer · error · ImageError

INVALID_RESPONSE_FORMAT

INVALID_RESPONSE_FORMAT

Error message

INVALID_RESPONSE_FORMAT

What it means

When a polled ModelScope task reaches SUCCEED status but output_images is missing or empty, the adapter throws INVALID_RESPONSE_FORMAT because a successful task produced no retrievable images.

Source

Thrown at packages/core/src/services/image/adapters/modelscope.ts:224

        try {
          const errorData = await response.json()
          if (errorData.error || errorData.message) {
            errorMessage = errorData.error || errorData.message
          }
        } catch {
          // 如果无法解析 JSON,使用默认错误信息
        }
        throw new ImageError(IMAGE_ERROR_CODES.GENERATION_FAILED, `Failed to poll task status: ${errorMessage}`)
      }

      const data = await response.json()
      const status = data.task_status

      if (status === 'SUCCEED') {
        // 任务成功,解析结果
        const outputImages = data.output_images || []
        if (outputImages.length === 0) {
          throw new ImageError(IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT)
        }

        const images = outputImages.map((imageUrl: string) => ({
          url: imageUrl,
          mimeType: 'image/png'
        }))

        return {
          images,
          metadata: {
            providerId: 'modelscope',
            modelId: config.modelId,
            configId: config.id,
            taskId
          }
        }
      } else if (status === 'FAILED' || status === 'ERROR' || status === 'CANCELLED' || status === 'CANCELED') {
        // 任务失败或被取消,提取错误信息

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Log the full task-status response to see where outputs actually live
  2. Check ModelScope docs for the current output field name
  3. Retry the generation — occasionally transient
  4. Report upstream if the field is consistently absent
Defensive patterns

Strategy: try-catch

Try / catch

try { ... } catch (e) {
  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT)
    // succeeded task with no outputs — retry generation once
}

Prevention

When it happens

Trigger: ModelScope reports task_status === 'SUCCEED' yet the response contains no output_images array (or it is empty).

Common situations: ModelScope bug or schema change renaming the output field; results stored but referenced elsewhere; server-side generation silently produced nothing while still marking success.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/169ed60237d89fde. Report an issue: GitHub.