{"record":{"id":"0e01f1c642c36c36","repo":"yikart/AiToEarn","slug":"error-0e01f1","errorCode":null,"errorMessage":"任务不存在或状态不正确","messagePattern":"任务不存在或状态不正确","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"project/aitoearn-electron/server/src/modules/task/adminUserTask.controller.ts","lineNumber":100,"sourceCode":"    const userTask = await this.userTaskService.getUserTaskInfoById(id);\n    if (!userTask) throw new NotFoundException('任务不存在');\n    return this.adminUserTaskService.verifyUserTaskRejected(userTask, {\n      verifierUserId: verifier.id,\n      ...data,\n    });\n  }\n\n  @ApiResult({ type: Boolean })\n  @Put('rollback/rejected/:id')\n  async rollbackUserTaskApproved(\n    @GetToken() verifier: TokenInfo,\n    @Param('id') id: string,\n    @Body() data: RejectedTaskDto,\n  ) {\n    const userTask = await this.userTaskService.getUserTaskInfoById(id);\n    if (!userTask) throw new NotFoundException('任务不存在');\n    if (userTask.status !== UserTaskStatus.PENDING)\n      throw new NotFoundException('任务不存在或状态不正确');\n\n    return this.adminUserTaskService.rollbackUserTaskApproved(userTask, {\n      verifierUserId: verifier.id,\n      ...data,\n    });\n  }\n\n  // 运行自动审核的任务\n  @ApiResult({ type: Boolean })\n  @Put('audit/auto/run/:id')\n  async runUserTaskAuditAuto(@Param('id') id: string) {\n    const userTaskInfo =\n      await this.adminUserTaskService.getUserTaskInfoById(id);\n    if (!userTaskInfo) throw new NotFoundException('任务不存在或状态不正确');\n\n    const { status, message, retry, data } =\n      await this.adminUserTaskService.autoAuditTask(id);\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-electron/server/src/modules/task/adminUserTask.controller.ts#L82-L118","documentation":"NestJS 404 (message '任务不存在或状态不正确') thrown when rolling back a user task whose status is not PENDING. Rollback is only allowed on pending submissions, so an already-approved/rejected record triggers this combined not-found-or-wrong-status error.","triggerScenarios":"Rollback call where userTask.status !== PENDING — e.g. attempting rollback after approval was finalized by the auto-audit flow or another admin.","commonSituations":"Trying to undo an approval that was already committed; racing with runUserTaskAuditAuto which may have advanced the status; stale admin page showing outdated status.","solutions":["Re-fetch the user task and only roll back while status is PENDING.","If the task is already APPROVED and must be undone, use the dedicated rollback-of-approved flow or a manual DB operation per business rules.","Serialize rollback with auto-audit so both cannot act on the same record simultaneously."],"exampleFix":"// before\nif (userTask.status !== UserTaskStatus.PENDING)\n  throw new NotFoundException('任务不存在或状态不正确');\n// after\nif (userTask.status !== UserTaskStatus.PENDING)\n  throw new AppHttpException(ErrHttpBack.user_task_err_status);","handlingStrategy":"validation","validationCode":"const ut = await api.getUserTask(id);\nif (!ut) throw new Error(`User task ${id} not found`);\nif (ut.status !== 'PENDING') throw new Error(`Cannot rollback: status is ${ut.status}`);","typeGuard":"function canRollback(t: { status: UserTaskStatus }): boolean {\n  return t.status === UserTaskStatus.PENDING;\n}","tryCatchPattern":"try {\n  await api.rollbackApproved(id, data);\n} catch (e) {\n  if (e.response?.status === 404) {\n    const cur = await api.getUserTask(id);\n    console.warn(`Rollback blocked; current status: ${cur?.status}`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Only offer rollback in the UI for PENDING items.","Coordinate with the auto-audit flow to avoid status races.","Return a distinct status-error code instead of a 404 for wrong-state records."],"tags":["state-machine","task-audit","concurrency"],"backgroundTag":"invalid-state-transition","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}