lima-vm/lima · error
failed to run %v: %w (stdout=%#q, stderr=%#q)
Error message
failed to run %v: %w (stdout=%#q, stderr=%#q)
What it means
Sysctl() runs `sysctl -n <name>` on Unix and captures stdout/stderr. Any non-zero exit of the sysctl binary (unknown OID, permission denied, truncated value) is returned as this error including the captured stdout and stderr, so the caller can distinguish 'unknown key' from 'permission denied'.
Source
Thrown at pkg/osutil/osutil_unix.go:35
"golang.org/x/sys/unix"
)
func Dup2(oldfd, newfd int) (err error) {
return unix.Dup2(oldfd, newfd)
}
func SignalName(sig os.Signal) string {
return unix.SignalName(sig.(syscall.Signal))
}
func Sysctl(ctx context.Context, name string) (string, error) {
var stderrBuf bytes.Buffer
cmd := exec.CommandContext(ctx, "sysctl", "-n", name)
cmd.Stderr = &stderrBuf
stdout, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to run %v: %w (stdout=%#q, stderr=%#q)", cmd.Args, err,
string(stdout), stderrBuf.String())
}
return strings.TrimSuffix(string(stdout), "\n"), nil
}
func IsEACCES(err error) bool {
return errors.Is(err, unix.EACCES)
}
// ProcessAlive reports whether the process with the given PID is still running.
func ProcessAlive(pid int) bool {
err := syscall.Kill(pid, 0)
return err == nil || errors.Is(err, syscall.EPERM)
}
View on GitHub (pinned to dd909d0973)
Solutions
- Check the stderr embedded in the error: 'unknown oid' means the key doesn't exist on this platform.
- Verify the key with `sysctl -n <name>` manually in the same environment.
- For permission errors, run privileged or pick a readable equivalent OID.
- Guard with per-platform key lists so platform-specific OIDs aren't queried on the wrong OS.
Example fix
// before
v, err := osutil.Sysctl(ctx, "vm.overcommit_memory") // fails on macOS
// after
if runtime.GOOS == "linux" {
v, err = osutil.Sysctl(ctx, "vm.overcommit_memory")
} Defensive patterns
Strategy: try-catch
Validate before calling
// check key readability before calling Sysctl
out, err := exec.Command("sysctl", "-n", name).Output()
_ = out
// if err != nil, the Sysctl call will fail the same way; choose a platform-specific key Try / catch
v, err := osutil.Sysctl(ctx, name)
if err != nil {
switch {
case strings.Contains(err.Error(), "unknown oid"):
log.Warnf("sysctl %s not present on this platform", name)
case strings.Contains(err.Error(), "permission denied"):
log.Warnf("sysctl %s requires root", name)
}
v = defaultValue
} Prevention
- Maintain per-OS sysctl key maps instead of querying the same key everywhere
- Read the embedded stderr to distinguish unknown-key vs permission errors
- Smoke-test sysctl keys on each target platform in CI
When it happens
Trigger: Sysctl(ctx, name) is invoked with a name that doesn't exist on this kernel, an unreadable (root-only) OID, or when sysctl writes data larger than an older kern.osrelease buffer allows — the subprocess exits non-zero.
Common situations: Querying a sysctl present on Linux but not macOS (or vice versa); reading root-only OIDs like kern.securelevel adjustments as unprivileged user; typos in the sysctl name; musl/alpine images where the sysctl binary differs.
Related errors
- --condition=boot is only supported on macOS
- failed to mount %#q on %#q: %w (output=%#q)
- failed to unmount %#q: %w (output=%#q)
- failed to create temp file: %w
- failed to write temp plist: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/443ecf07c0a27d79.
Report an issue: GitHub.