{"record":{"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":null,"httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/core.ts","lineNumber":1279,"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":1261,"sourceCodeEnd":1297,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/core.ts#L1261-L1297","documentation":"rerunTask looks up the task by id in state.idMap; if the id was never collected/registered it throws. This is a watcher-driven API, so the error means an id was supplied that Vitest never indexed — typically a stale, fabricated, or post-deletion id.","triggerScenarios":"Calling rerunTask(id) (usually via watcher/IPC/programmatic API) with an id that is not a key in state.idMap, e.g. after the source file was removed, after state was cleared, or with a hardcoded/external id.","commonSituations":"Watcher rerun after file deletion; programmatic API misuse with hardcoded ids; stale id captured from a previous run; rerun triggered during teardown.","solutions":["Guard with state.idMap.has(id) (or state.getTask(id)) before calling rerunTask.","Re-run collection so the idMap is rebuilt before rerunning.","Ensure the source file still exists and was imported successfully in the last run."],"exampleFix":"// before\nawait vitest.rerunTask(id)\n\n// after\nif (!vitest.state.idMap.has(id)) {\n  await vitest.collect() // rebuild idMap\n}\nif (vitest.state.idMap.has(id)) {\n  await vitest.rerunTask(id)\n}","handlingStrategy":"validation","validationCode":"function taskExists(state, id) {\n  return state.idMap.has(id)\n}\n// before: if (!taskExists(vitest.state, id)) await vitest.collect()","typeGuard":"function isKnownTaskId(state, id): id is string {\n  return typeof id === 'string' && state.idMap.has(id)\n}","tryCatchPattern":null,"preventionTips":["Always (re)collect before rerunning tasks so the idMap is fresh.","Never persist task ids across runs; ids are run-scoped.","Guard rerunTask callers (watcher/IPC handlers) with state.idMap.has(id)."],"tags":["watcher","rerun","task-lookup"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}