chenhg5/cc-connect · error

remove task script: %w

Error message

remove task script: %w

What it means

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.

Source

Thrown at daemon/windows.go:95

	if err := createWindowsTask(scriptPath); err != nil {
		return err
	}

	if err := m.Start(); err != nil {
		return fmt.Errorf("start task: %w", err)
	}
	return nil
}

func (*schtasksManager) Uninstall() error {
	if err := stopWindowsTask(); err != nil {
		slog.Warn("schtasks: stop task failed", "error", err)
	}
	if err := deleteWindowsTask(); err != nil {
		return err
	}
	if err := os.Remove(windowsTaskScriptPath()); err != nil && !os.IsNotExist(err) {
		return fmt.Errorf("remove task script: %w", err)
	}
	return nil
}

func (*schtasksManager) Start() error {
	return startWindowsTask()
}

func (*schtasksManager) Stop() error {
	if err := stopWindowsTask(); err != nil {
		return err
	}
	return nil
}

func (*schtasksManager) Restart() error {
	if err := stopWindowsTask(); err != nil {
		slog.Warn("schtasks: stop before restart failed", "error", err)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Ensure the scheduled task and any running cc-connect process are fully stopped, then run Uninstall again.
  2. Delete the script manually at the path reported by windowsTaskScriptPath() and re-run Uninstall.
  3. Check and clear the read-only attribute (`attrib -r <script>`).
  4. Re-run the uninstall from the same (or elevated) user that installed it.

Example fix

// before
if err := os.Remove(windowsTaskScriptPath()); err != nil && !os.IsNotExist(err) {
	return fmt.Errorf("remove task script: %w", err)
}
// after: surface the offending path for manual cleanup
script := windowsTaskScriptPath()
if err := os.Remove(script); err != nil && !os.IsNotExist(err) {
	return fmt.Errorf("remove task script %s: %w", script, err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

script := daemon.WindowsTaskScriptPath() // if exposed
if info, err := os.Stat(script); err == nil {
	if info.Mode().Perm()&0200 == 0 {
		os.Chmod(script, 0600) // clear read-only before uninstall
	}
}

Try / catch

if err := daemon.Uninstall(); err != nil {
	if strings.Contains(err.Error(), "remove task script") {
		slog.Warn("script left on disk; stop processes and delete manually", "error", err)
	}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/651a19f97f65f082. Report an issue: GitHub.