{"record":{"id":"74887c10851affe6","repo":"chenhg5/cc-connect","slug":"start-s-w-74887c","errorCode":null,"errorMessage":"start: %s (%w)","messagePattern":"start: (.+?) \\(%w\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/systemd.go","lineNumber":108,"sourceCode":"\tif _, err := runSystemctl(m.sysArgs(\"disable\", \"--now\", systemdServiceName)...); err != nil {\n\t\tslog.Warn(\"systemd: disable failed\", \"error\", err)\n\t}\n\n\tunitPath := m.unitPath()\n\tif err := os.Remove(unitPath); err != nil && !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"remove unit: %w\", err)\n\t}\n\n\tif _, err := runSystemctl(m.sysArgs(\"daemon-reload\")...); err != nil {\n\t\tslog.Warn(\"systemd: daemon-reload failed\", \"error\", err)\n\t}\n\treturn nil\n}\n\nfunc (m *systemdManager) Start() error {\n\tout, err := runSystemctl(m.sysArgs(\"start\", systemdServiceName)...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"start: %s (%w)\", out, err)\n\t}\n\treturn nil\n}\n\nfunc (m *systemdManager) Stop() error {\n\tout, err := runSystemctl(m.sysArgs(\"stop\", systemdServiceName)...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"stop: %s (%w)\", out, err)\n\t}\n\treturn nil\n}\n\nfunc (m *systemdManager) Restart() error {\n\tout, err := runSystemctl(m.sysArgs(\"restart\", systemdServiceName)...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"restart: %s (%w)\", out, err)\n\t}\n\treturn nil","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L90-L126","documentation":"Start() wraps a failure of `systemctl start cc-connect`, including systemctl's stdout in the message. It means the service could not be started, either because systemctl itself failed to talk to systemd or because the service unit failed to activate.","triggerScenarios":"Calling Start when the unit is not installed, systemd is not running (WSL2/containers), the service is masked, or the service's ExecStart fails immediately.","commonSituations":"Start called before Install; WSL2 without systemd=true in wsl.conf; the configured agent binary missing from PATH for the service user; unit disabled and masked by an admin.","solutions":["Read the embedded systemctl stdout for the activation failure reason.","Ensure the unit is installed: `systemctl cat cc-connect` (install first if missing).","Confirm systemd is running: `systemctl is-system-running`; enable it in WSL2 via /etc/wsl.conf.","Check service logs: `journalctl -u cc-connect -e` for ExecStart errors."],"exampleFix":"// before\nmgr.Start() // start: Failed to start cc-connect.service: Unit is masked\n// after\nif st, _ := mgr.Status(); st == nil || !st.Running {\n    return fmt.Errorf(\"cc-connect unit not installed; run install first\")\n}\nmgr.Start()","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(mgr.unitPath()); err != nil {\n    return fmt.Errorf(\"unit not installed; run install first\")\n}\nif out, err := exec.Command(\"systemctl\", \"is-system-running\").Output(); err != nil {\n    return fmt.Errorf(\"systemd unavailable (%s): %w\", strings.TrimSpace(string(out)), err)\n}","typeGuard":"func serviceStartable(unitPath string) bool {\n    if _, err := os.Stat(unitPath); err != nil { return false }\n    return exec.Command(\"systemctl\", \"is-system-running\").Run() == nil\n}","tryCatchPattern":"if err := mgr.Start(); err != nil {\n    if strings.Contains(err.Error(), \"not loaded\") || strings.Contains(err.Error(), \"not found\") {\n        return fmt.Errorf(\"install the unit first: %w\", err)\n    }\n    return err\n}","preventionTips":["Install the unit before calling Start.","Enable systemd in WSL2 before daemon operations.","Check journalctl -u cc-connect when start fails.","Avoid masking the unit with admin overrides."],"tags":["systemd","go","service","process"],"backgroundTag":"connection-refused","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"}