chenhg5/cc-connect · error
stop: %s (%w)
Error message
stop: %s (%w)
What it means
Stop() wraps a failure of `systemctl stop cc-connect`, including systemctl's stdout. It means the service could not be stopped, typically because systemctl cannot reach the systemd manager or the unit is not loaded.
Source
Thrown at daemon/systemd.go:116
if _, err := runSystemctl(m.sysArgs("daemon-reload")...); err != nil {
slog.Warn("systemd: daemon-reload failed", "error", err)
}
return nil
}
func (m *systemdManager) Start() error {
out, err := runSystemctl(m.sysArgs("start", systemdServiceName)...)
if err != nil {
return fmt.Errorf("start: %s (%w)", out, err)
}
return nil
}
func (m *systemdManager) Stop() error {
out, err := runSystemctl(m.sysArgs("stop", systemdServiceName)...)
if err != nil {
return fmt.Errorf("stop: %s (%w)", out, err)
}
return nil
}
func (m *systemdManager) Restart() error {
out, err := runSystemctl(m.sysArgs("restart", systemdServiceName)...)
if err != nil {
return fmt.Errorf("restart: %s (%w)", out, err)
}
return nil
}
func (m *systemdManager) Status() (*Status, error) {
st := &Status{Platform: m.Platform()}
unitPath := m.unitPath()
if _, err := os.Stat(unitPath); err != nil {
return st, nilView on GitHub (pinned to 4000b2338a)
Solutions
- Read the embedded stdout; if it says the unit is not loaded, treat the service as already stopped.
- Verify systemd is reachable: `systemctl is-system-running`.
- Run with sufficient privileges (sudo) for system units.
- Fall back gracefully: check `systemctl is-active cc-connect` before/after Stop.
Example fix
// before
mgr.Stop() // stop: Unit cc-connect.service not loaded.
// after
if out, err := mgr.Stop(); err != nil && strings.Contains(out, "not loaded") {
return nil // already stopped
} else if err != nil {
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
active, err := exec.Command("systemctl", "is-active", "cc-connect").Output()
if err == nil && strings.TrimSpace(string(active)) == "inactive" {
return nil // already stopped
} Type guard
func serviceLoaded() bool {
out, err := exec.Command("systemctl", "is-active", "cc-connect").Output()
return err == nil && strings.TrimSpace(string(out)) != "unknown"
} Try / catch
if err := mgr.Stop(); err != nil {
if strings.Contains(err.Error(), "not loaded") {
return nil // idempotent stop
}
return err
} Prevention
- Make Stop calls idempotent: ignore 'unit not loaded' errors.
- Verify systemd reachability before stop operations.
- Don't call Stop from inside the service's own ExecStart process path.
- Use `systemctl is-active` as a pre-check.
When it happens
Trigger: Calling Stop when systemd is not running, the unit was never installed/loaded, or the caller lacks privileges; also during shutdown when the system manager is going away.
Common situations: Calling Stop from within the service itself in a constrained environment; unit already removed but Stop invoked on stale state; WSL2 session where systemd isn't PID 1.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- systemctl %s: %s (%w)
- start: %s (%w)
- restart: %s (%w)
- antigravitySession: stdout pipe: %w
- antigravitySession: start: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/1042bb71bbca0506.
Report an issue: GitHub.