{"record":{"id":"38eb1654c189fd4a","repo":"chenhg5/cc-connect","slug":"create-log-dir-w-38eb16","errorCode":null,"errorMessage":"create log dir: %w","messagePattern":"create log dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/systemd.go","lineNumber":58,"sourceCode":"\t}\n\treturn &systemdManager{system: false}, nil\n}\n\nfunc (m *systemdManager) Platform() string {\n\tif m.system {\n\t\treturn \"systemd (system)\"\n\t}\n\treturn \"systemd (user)\"\n}\n\nfunc (m *systemdManager) Install(cfg Config) error {\n\tunitPath := m.unitPath()\n\n\tif err := os.MkdirAll(filepath.Dir(unitPath), 0755); err != nil {\n\t\treturn fmt.Errorf(\"create systemd dir: %w\", err)\n\t}\n\tif err := os.MkdirAll(filepath.Dir(cfg.LogFile), 0755); err != nil {\n\t\treturn fmt.Errorf(\"create log dir: %w\", err)\n\t}\n\n\tunit := m.buildUnit(cfg)\n\t// 0600: unit file may contain captured secret values (config.toml ${ENV}\n\t// placeholders and any EnvDiscoverer extension output). For system-level\n\t// units (/etc/systemd/system/) the file is owned by root and remains\n\t// readable by root only; for user-level units under\n\t// ~/.config/systemd/user it remains owner-only. WriteFile only applies\n\t// perm on create, so Chmod afterwards is required to harden reinstalls\n\t// of pre-existing 0644 units from earlier cc-connect versions.\n\tif err := os.WriteFile(unitPath, []byte(unit), 0600); err != nil {\n\t\treturn fmt.Errorf(\"write unit file: %w\", err)\n\t}\n\tif err := os.Chmod(unitPath, 0600); err != nil {\n\t\treturn fmt.Errorf(\"chmod unit file: %w\", err)\n\t}\n\n\tfor _, cmdArgs := range [][]string{","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L40-L76","documentation":"Install() wraps os.MkdirAll failure for the configured log file's parent directory. It means cfg.LogFile's directory could not be created, so the service would have nowhere to write logs. This is a config-driven path, so bad configuration is the usual cause.","triggerScenarios":"Calling Install with a Config whose LogFile points into an unwritable or malformed location: non-existent parent under a read-only mount, a file occupying the parent path, or an empty/invalid LogFile path.","commonSituations":"config.toml sets log_file to /var/log/cc-connect/cc.log but the user lacks root; a typo like log_file = \"~/cc.log\" evaluated with an unexpanded '~'; log dir deleted on a tmpfs after reboot.","solutions":["Fix log_file in config.toml to a writable absolute path (expand ~ yourself).","Pre-create the directory with correct permissions: `sudo mkdir -p /var/log/cc-connect`.","Run with elevated privileges if the log path requires root.","Point LogFile at the user's home directory for user-level installs."],"exampleFix":"// before\ncfg := Config{LogFile: \"/var/log/cc-connect/cc.log\"} // non-root cannot mkdir /var/log/cc-connect\n// after\nhome, _ := os.UserHomeDir()\ncfg := Config{LogFile: filepath.Join(home, \".local\", \"state\", \"cc-connect\", \"cc.log\")}","handlingStrategy":"validation","validationCode":"logDir := filepath.Dir(cfg.LogFile)\nif logDir == \"\" || logDir == \".\" {\n    return fmt.Errorf(\"LogFile must be an absolute path\")\n}\nif err := os.MkdirAll(logDir, 0755); err != nil {\n    return fmt.Errorf(\"log dir not creatable: %w\", err)\n}\nf, err := os.OpenFile(cfg.LogFile, os.O_APPEND|os.O_CREATE, 0600)\nif err == nil { f.Close() }","typeGuard":"func logPathWritable(p string) bool {\n    dir := filepath.Dir(p)\n    if err := os.MkdirAll(dir, 0755); err != nil { return false }\n    f, err := os.CreateTemp(dir, \".probe\")\n    if err != nil { return false }\n    f.Close(); os.Remove(f.Name())\n    return true\n}","tryCatchPattern":"if err := mgr.Install(cfg); err != nil {\n    if strings.Contains(err.Error(), \"create log dir\") {\n        return fmt.Errorf(\"fix log_file in config.toml: %w\", err)\n    }\n    return err\n}","preventionTips":["Use absolute, ~-expanded paths for log_file in config.toml.","Probe-create the log directory before install.","Keep logs under user-writable locations for user-level installs.","Avoid log paths on tmpfs that vanish across reboots."],"tags":["go","systemd","filesystem","logging"],"backgroundTag":"mkdir-permission-denied","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"}