Skip to content

Commit 21e0757

Browse files
author
aheizi
committed
catch Task not found error
1 parent 77ae24f commit 21e0757

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,43 +2271,51 @@ export class ClineProvider implements vscode.WebviewViewProvider {
22712271

22722272
// this function deletes a task from task hidtory, and deletes it's checkpoints and delete the task folder
22732273
async deleteTaskWithId(id: string) {
2274-
// get the task directory full path
2275-
const { taskDirPath } = await this.getTaskWithId(id)
2276-
2277-
// remove task from stack if it's the current task
2278-
if (id === this.getCurrentCline()?.taskId) {
2279-
// if we found the taskid to delete - call finish to abort this task and allow a new task to be started,
2280-
// if we are deleting a subtask and parent task is still waiting for subtask to finish - it allows the parent to resume (this case should neve exist)
2281-
await this.finishSubTask(`Task failure: It was stopped and deleted by the user.`)
2282-
}
2274+
try {
2275+
// Try to get the task directory full path
2276+
const { taskDirPath } = await this.getTaskWithId(id)
2277+
2278+
// remove task from stack if it's the current task
2279+
if (id === this.getCurrentCline()?.taskId) {
2280+
// if we found the taskid to delete - call finish to abort this task and allow a new task to be started,
2281+
// if we are deleting a subtask and parent task is still waiting for subtask to finish - it allows the parent to resume (this case should neve exist)
2282+
await this.finishSubTask(`Task failure: It was stopped and deleted by the user.`)
2283+
}
22832284

2284-
// delete task from the task history state
2285-
await this.deleteTaskFromState(id)
2285+
// delete task from the task history state
2286+
await this.deleteTaskFromState(id)
22862287

2287-
// get the base directory of the project
2288-
const baseDir = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
2288+
// get the base directory of the project
2289+
const baseDir = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
22892290

2290-
// Delete associated shadow repository or branch.
2291-
// TODO: Store `workspaceDir` in the `HistoryItem` object.
2292-
const globalStorageDir = this.contextProxy.globalStorageUri.fsPath
2293-
const workspaceDir = baseDir ?? ""
2291+
// Delete associated shadow repository or branch.
2292+
const globalStorageDir = this.contextProxy.globalStorageUri.fsPath
2293+
const workspaceDir = baseDir ?? ""
22942294

2295-
try {
2296-
await ShadowCheckpointService.deleteTask({ taskId: id, globalStorageDir, workspaceDir })
2297-
} catch (error) {
2298-
console.error(
2299-
`[deleteTaskWithId${id}] failed to delete associated shadow repository or branch: ${error instanceof Error ? error.message : String(error)}`,
2300-
)
2301-
}
2295+
try {
2296+
await ShadowCheckpointService.deleteTask({ taskId: id, globalStorageDir, workspaceDir })
2297+
} catch (error) {
2298+
console.error(
2299+
`[deleteTaskWithId${id}] failed to delete associated shadow repository or branch: ${error instanceof Error ? error.message : String(error)}`,
2300+
)
2301+
}
23022302

2303-
// delete the entire task directory including checkpoints and all content
2304-
try {
2305-
await fs.rm(taskDirPath, { recursive: true, force: true })
2306-
console.log(`[deleteTaskWithId${id}] removed task directory`)
2303+
// delete the entire task directory including checkpoints and all content
2304+
try {
2305+
await fs.rm(taskDirPath, { recursive: true, force: true })
2306+
console.log(`[deleteTaskWithId${id}] removed task directory`)
2307+
} catch (error) {
2308+
console.error(
2309+
`[deleteTaskWithId${id}] failed to remove task directory: ${error instanceof Error ? error.message : String(error)}`,
2310+
)
2311+
}
23072312
} catch (error) {
2308-
console.error(
2309-
`[deleteTaskWithId${id}] failed to remove task directory: ${error instanceof Error ? error.message : String(error)}`,
2310-
)
2313+
// If task is not found, just remove it from state
2314+
if (error instanceof Error && error.message === "Task not found") {
2315+
await this.deleteTaskFromState(id)
2316+
return
2317+
}
2318+
throw error
23112319
}
23122320
}
23132321

0 commit comments

Comments
 (0)