Skip to content

Commit 58b0230

Browse files
fix(launchd): surface bootstrap/bootout failures instead of swallowing them
1 parent 432bc2f commit 58b0230

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

internal/launchd/launchd.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ func Install(exec executor.Executor, log *progress.Logger) error {
139139
if !exec.IsRoot() {
140140
domain = fmt.Sprintf("gui/%d", os.Getuid())
141141
}
142-
_, _, exitCode, err := exec.Run(ctx, "launchctl", "bootstrap", domain, plistPath)
143-
log.Debug("launchctl bootstrap %q %q: exit_code=%d err=%v", domain, plistPath, exitCode, err)
144-
if err != nil || exitCode != 0 {
145-
return fmt.Errorf("failed to bootstrap launchd configuration")
142+
_, stderr, exitCode, err := exec.Run(ctx, "launchctl", "bootstrap", domain, plistPath)
143+
log.Debug("launchctl bootstrap %q %q: exit_code=%d err=%v stderr=%q", domain, plistPath, exitCode, err, stderr)
144+
if err != nil {
145+
return fmt.Errorf("launchctl bootstrap failed: %w", err)
146+
}
147+
if exitCode != 0 {
148+
return fmt.Errorf("launchctl bootstrap failed (exit code %d): %s", exitCode, strings.TrimSpace(stderr))
146149
}
147150

148151
log.Progress("launchd configuration completed successfully")
@@ -182,9 +185,16 @@ func doUninstall(ctx context.Context, exec executor.Executor, log *progress.Logg
182185
domain = fmt.Sprintf("gui/%d", os.Getuid())
183186
}
184187
target := domain + "/" + label
185-
_, _, exitCode, err := exec.Run(ctx, "launchctl", "bootout", target)
186-
log.Debug("launchctl bootout %q: exit_code=%d err=%v", target, exitCode, err)
187-
log.Progress("Unloaded launchd agent")
188+
_, stderr, exitCode, err := exec.Run(ctx, "launchctl", "bootout", target)
189+
log.Debug("launchctl bootout %q: exit_code=%d err=%v stderr=%q", target, exitCode, err, stderr)
190+
switch {
191+
case err != nil:
192+
log.Warn("launchctl bootout failed: %v — the running service may persist until reboot; plist will still be removed", err)
193+
case exitCode != 0:
194+
log.Warn("launchctl bootout failed (exit code %d): %s — the running service may persist until reboot; plist will still be removed", exitCode, strings.TrimSpace(stderr))
195+
default:
196+
log.Progress("Unloaded launchd agent")
197+
}
188198
}
189199

190200
// Remove plist

0 commit comments

Comments
 (0)