yikart/AiToEarn · warning · NotFoundException

任务不存在

Error message

任务不存在

What it means

getTaskStatus looks up an async image generation task by its AI log id. It throws NotFoundException('任务不存在') when no log record with that id exists, or the record exists but is not of type AiLogType.Image — i.e. the id never belonged to an image task.

Source

Thrown at project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/image/image.service.ts:489

      type: AiLogType.Image,
      retry: this.getImageModelRetry(params.model, 'edit'),
      request: { ...params, user: userId },
      taskType: 'edit',
    })

    return {
      logId: log.id,
      status: AiLogStatus.Generating,
    }
  }

  /**
   * 查询任务状态
   */
  async getTaskStatus(logId: string) {
    const log = await this.aiLogRepo.getById(logId)
    if (!log || log.type !== AiLogType.Image) {
      throw new NotFoundException('任务不存在')
    }
    const response = log.response as ImageAiLogResponse | undefined

    // 提取图片信息
    let images: AiLogImageResult[] | undefined
    if (response?.list?.length) {
      images = response.list
    }
    else if (response?.images?.length) {
      images = response.images
    }
    else if (response?.image) {
      images = [{ url: response.image }]
    }
    else if (response?.imageUrl) {
      images = [{ url: response.imageUrl }]
    }

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Use the exact logId returned when the image task was submitted, not the provider-side task id
  2. Verify the id belongs to an image generation task (AiLogType.Image), not another AI log type
  3. Check the DB/aiLogRepo record exists for that id; if recently created, rule out replica lag
  4. If records expire, re-check within the retention window or persist the id on your side

Example fix

// before
const status = await imageService.getTaskStatus(providerTaskId)
// after
const status = await imageService.getTaskStatus(submitResult.logId) // id returned by the submit call
Defensive patterns

Strategy: try-catch

Type guard

function isImageTaskLog(log: AiLog | undefined): log is AiLog & { type: AiLogType.Image } {
  return !!log && log.type === AiLogType.Image
}

Try / catch

try {
  const status = await imageService.getTaskStatus(logId)
} catch (e) {
  if (e instanceof NotFoundException) {
    return { state: 'unknown', reason: 'task id not found or not an image task' }
  }
  throw e
}

Prevention

When it happens

Trigger: Polling getTaskStatus with an id that was never created (submit failed), a typo'd/truncated logId, passing an id from a different task type (e.g. a video or text AI log), or querying after log retention cleanup removed the record.

Common situations: Client polls with the wrong identifier (e.g. upstream provider task id instead of the internal logId); record pruned by data-retention; cross-service id confusion.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/a0876c87e6cac424. Report an issue: GitHub.