{"id":"a2fcf1afa2133f04","repo":"vitest-dev/vitest","slug":"task-id-was-not-found","errorCode":null,"errorMessage":"Task ${id} was not found","messagePattern":"Task (.+?) was not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/core.ts","lineNumber":1281,"sourceCode":"      files = files.filter(file => filteredFiles.some(f => f.moduleId === file))\n    }\n\n    const specifications = files.flatMap(file => this.getModuleSpecifications(file))\n    await Promise.all([\n      this.report('onWatcherRerun', files, trigger),\n      ...this._onUserTestsRerun.map(fn => fn(specifications)),\n    ])\n    const testResult = await this.runFiles(specifications, allTestsRun)\n\n    await this.report('onWatcherStart', this.state.getFiles(files))\n    return testResult\n  }\n\n  /** @internal */\n  async rerunTask(id: string): Promise<void> {\n    const task = this.state.idMap.get(id)\n    if (!task) {\n      throw new Error(`Task ${id} was not found`)\n    }\n\n    const reportedTask = this.state.getReportedEntityById(id)\n    if (!reportedTask) {\n      throw new Error(`Test specification for task ${id} was not found`)\n    }\n\n    const specifications = [reportedTask.toTestSpecification()]\n    await Promise.all([\n      this.report(\n        'onWatcherRerun',\n        [task.file.filepath],\n        'tasks' in task ? 'rerun suite' : 'rerun test',\n      ),\n      ...this._onUserTestsRerun.map(fn => fn(specifications)),\n    ])\n    await this.runFiles(specifications, false)\n    await this.report(","sourceCodeStart":1263,"sourceCodeEnd":1299,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/core.ts#L1263-L1299","documentation":"rerunTask(id) (core.ts:1281) is an internal watcher entry point. It looks the id up in state.idMap and throws if no task with that id was ever registered. The id must come from vitest's own task state, not from user code.","triggerScenarios":"Watch-mode rerun triggered for a task id not present in state.idMap — e.g. after the task's file was deleted, after state was cleared, or from a stale externally-supplied id.","commonSituations":"Calling the internal rerunTask directly with an arbitrary string; rerunning a task whose file was just removed; out-of-sync state in a custom watcher integration.","solutions":["Use ids obtained from vitest.state.idMap / state.getReportedEntityById, never hand-rolled strings.","Ensure tasks are loaded (files discovered) before invoking a rerun.","Prefer the public file-level rerun APIs (rerunFiles / changeNamePattern) over the internal rerunTask."],"exampleFix":"// before\nvitest.rerunTask(someIdFromUnknownSource)\n\n// after\nconst task = vitest.state.idMap.get(someId)\nif (task) await vitest.rerunTask(someId)","handlingStrategy":"validation","validationCode":"if (!vitest.state.idMap.has(id)) {\n  throw new Error(`Refusing to rerun unknown task id: ${id}`)\n}\nawait vitest.rerunTask(id)","typeGuard":"function taskExists(vitest: Vitest, id: string): boolean {\n  return vitest.state.idMap.has(id)\n}","tryCatchPattern":null,"preventionTips":["Only rerun ids sourced from vitest.state.idMap.","Avoid calling the internal rerunTask; prefer the public rerunFiles API.","Re-discover files if state may have been cleared."],"tags":["watch","tasks","internal","state"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}