{"record":{"id":"651a19f97f65f082","repo":"chenhg5/cc-connect","slug":"remove-task-script-w","errorCode":null,"errorMessage":"remove task script: %w","messagePattern":"remove task script: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/windows.go","lineNumber":95,"sourceCode":"\tif err := createWindowsTask(scriptPath); err != nil {\n\t\treturn err\n\t}\n\n\tif err := m.Start(); err != nil {\n\t\treturn fmt.Errorf(\"start task: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (*schtasksManager) Uninstall() error {\n\tif err := stopWindowsTask(); err != nil {\n\t\tslog.Warn(\"schtasks: stop task failed\", \"error\", err)\n\t}\n\tif err := deleteWindowsTask(); err != nil {\n\t\treturn err\n\t}\n\tif err := os.Remove(windowsTaskScriptPath()); err != nil && !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"remove task script: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (*schtasksManager) Start() error {\n\treturn startWindowsTask()\n}\n\nfunc (*schtasksManager) Stop() error {\n\tif err := stopWindowsTask(); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc (*schtasksManager) Restart() error {\n\tif err := stopWindowsTask(); err != nil {\n\t\tslog.Warn(\"schtasks: stop before restart failed\", \"error\", err)","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/windows.go#L77-L113","documentation":"Uninstall() on Windows wraps a failure to os.Remove the task script file (windowsTaskScriptPath) after the scheduled task itself was deleted. The error is ignored when the file simply does not exist (os.IsNotExist); this error means the file exists but could not be removed. The script path is therefore left on disk.","triggerScenarios":"Calling daemon.Uninstall on Windows when the generated PowerShell script file is locked by another process (still-executing task), is read-only, or the user lacks write permission on its directory.","commonSituations":"Uninstalling while the daemon/task is still running and holds the script open; the file was made read-only; antivirus quarantining/locking .ps1 files; installing under an admin account and uninstalling as a normal user.","solutions":["Ensure the scheduled task and any running cc-connect process are fully stopped, then run Uninstall again.","Delete the script manually at the path reported by windowsTaskScriptPath() and re-run Uninstall.","Check and clear the read-only attribute (`attrib -r <script>`).","Re-run the uninstall from the same (or elevated) user that installed it."],"exampleFix":"// before\nif err := os.Remove(windowsTaskScriptPath()); err != nil && !os.IsNotExist(err) {\n\treturn fmt.Errorf(\"remove task script: %w\", err)\n}\n// after: surface the offending path for manual cleanup\nscript := windowsTaskScriptPath()\nif err := os.Remove(script); err != nil && !os.IsNotExist(err) {\n\treturn fmt.Errorf(\"remove task script %s: %w\", script, err)\n}","handlingStrategy":"try-catch","validationCode":"script := daemon.WindowsTaskScriptPath() // if exposed\nif info, err := os.Stat(script); err == nil {\n\tif info.Mode().Perm()&0200 == 0 {\n\t\tos.Chmod(script, 0600) // clear read-only before uninstall\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := daemon.Uninstall(); err != nil {\n\tif strings.Contains(err.Error(), \"remove task script\") {\n\t\tslog.Warn(\"script left on disk; stop processes and delete manually\", \"error\", err)\n\t}\n}","preventionTips":["Fully stop the daemon/task before uninstalling so the script is not locked.","Do not set the script file read-only or let AV quarantine it.","Uninstall with the same account that ran the install."],"tags":["windows","file-remove","uninstall","cleanup"],"backgroundTag":"file-remove-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}