chenhg5/cc-connect · error

create log dir: %w

Error message

create log dir: %w

What it means

In schtasksManager.Install (daemon/windows.go), after creating the data dir the manager creates the parent directory of the configured log file (os.MkdirAll(filepath.Dir(cfg.LogFile), 0755)); any failure is wrapped as "create log dir: %w". It means the directory that should hold the daemon's log file could not be created, so install aborts before writing the task script.

Source

Thrown at daemon/windows.go:47

}

type schtasksManager struct{}

func newPlatformManager() (Manager, error) {
	if _, err := exec.LookPath("powershell.exe"); err != nil {
		return nil, fmt.Errorf("powershell.exe not found: Windows Task Scheduler management requires PowerShell")
	}
	return &schtasksManager{}, nil
}

func (*schtasksManager) Platform() string { return "schtasks" }

func (m *schtasksManager) Install(cfg Config) error {
	if err := os.MkdirAll(DefaultDataDir(), 0755); err != nil {
		return fmt.Errorf("create data dir: %w", err)
	}
	if err := os.MkdirAll(filepath.Dir(cfg.LogFile), 0755); err != nil {
		return fmt.Errorf("create log dir: %w", err)
	}

	scriptPath := windowsTaskScriptPath()
	// 0644 has weak semantics on Windows; the file ACL is what matters.
	// We still write 0600 so the file's POSIX bits do not advertise read
	// access, and rely on the user's own profile ACLs for primary defense
	// (the script lives under %USERPROFILE%\.cc-connect by default).
	// WriteFile only applies perm on create, so Chmod the existing file
	// after writing to harden reinstalls of pre-existing 0644 scripts.
	if err := os.WriteFile(scriptPath, []byte(buildWindowsTaskScript(cfg)), 0600); err != nil {
		return fmt.Errorf("write task script: %w", err)
	}
	if err := os.Chmod(scriptPath, 0600); err != nil {
		return fmt.Errorf("chmod task script: %w", err)
	}

	if err := stopWindowsTask(); err != nil {
		slog.Warn("schtasks: stop existing task failed", "error", err)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix the log file path in config.toml so its parent directory exists or can be created on a writable local volume
  2. Manually create the directory: `mkdir <parent-of-LogFile>` and grant the account write access (`icacls <dir> /grant ...`)
  3. Check the wrapped cause: "Access is denied" → ACL issue; "The system cannot find the path" → bad drive/typo
  4. If a file already occupies the directory path, rename or delete it, then rerun install

Example fix

// before (config.toml)
log_file = "E:\\cc-connect\\cc.log"   // E: does not exist
// error: create log dir: mkdir E:\: The system cannot find the path specified.
// after
log_file = "C:\\Users\\me\\.cc-connect\\cc.log"
$ cc-connect daemon install
Defensive patterns

Strategy: validation

Validate before calling

logDir := filepath.Dir(cfg.LogFile)
if st, err := os.Stat(logDir); err == nil && !st.IsDir() {
    log.Fatalf("log path %s conflicts with an existing file", logDir)
}
if err := os.MkdirAll(logDir, 0o755); err != nil {
    log.Fatalf("cannot create log dir %s: %v — use a writable local path in config.toml", logDir, err)
}

Try / catch

if err := daemon.Install(cfg); err != nil && strings.Contains(err.Error(), "create log dir") {
    return fmt.Errorf("fix log_file in config.toml (parent dir must be creatable on a writable volume): %w", err)
}

Prevention

When it happens

Trigger: `cc-connect daemon install` with a Config.LogFile whose parent directory cannot be created — bad drive letter in the configured path, permission denied on the target folder, an existing file where a directory is expected, or a path with illegal characters.

Common situations: Config pointing the log file at D:\logs when D: is a removable/absent drive; log dir on a network share without write access; typo'd config (e.g. log_file = "C:\\log.txt.bak\\cc.log"); running under a service account lacking rights to the configured folder.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


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