{"record":{"id":"9e37a76daeef99d2","repo":"zeroclaw-labs/zeroclaw","slug":"tail-exited-with-non-zero-status","errorCode":null,"errorMessage":"tail exited with non-zero status","messagePattern":"tail exited with non-zero status","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-runtime/src/service/mod.rs","lineNumber":988,"sourceCode":"    let log_file = if stderr_log.exists() {\n        stderr_log\n    } else if stdout_log.exists() {\n        stdout_log\n    } else {\n        bail!(\n            \"No log files found in {}. Is the service installed?\",\n            logs_dir.display()\n        );\n    };\n\n    if follow {\n        let status = Command::new(\"tail\")\n            .args([\"-n\", &lines.to_string(), \"-f\"])\n            .arg(&log_file)\n            .status()\n            .context(\"Failed to run tail\")?;\n        if !status.success() {\n            bail!(\"tail exited with non-zero status\");\n        }\n    } else {\n        let status = Command::new(\"tail\")\n            .args([\"-n\", &lines.to_string()])\n            .arg(&log_file)\n            .status()\n            .context(\"Failed to run tail\")?;\n        if !status.success() {\n            bail!(\"tail exited with non-zero status\");\n        }\n    }\n    Ok(())\n}\n\nfn logs_linux(config: &Config, init_system: InitSystem, lines: usize, follow: bool) -> Result<()> {\n    match init_system {\n        InitSystem::Systemd => {\n            let args = linux_journalctl_args(config, lines, follow);","sourceCodeStart":970,"sourceCodeEnd":1006,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-runtime/src/service/mod.rs#L970-L1006","documentation":"In follow mode, logs_macos shells out to 'tail -n N -f <logfile>'. A non-zero tail exit is propagated as this error. Follow mode normally blocks until interrupted, so a non-zero exit usually means tail could not open or keep reading the file (deleted, rotated away, permission denied) or that tail is missing from PATH.","triggerScenarios":"The log file is deleted or rotated between the existence check and tail startup; the file is unreadable to the current user; a stripped PATH inside the calling environment leaves 'tail' unresolved.","commonSituations":"Log rotation while following; permissions changed after install; running under a minimal environment (launchd agent, restricted shell) without coreutils in PATH.","solutions":["Re-run 'zeroclaw service logs' after the file reappears","Verify the file with ls -l on the plist's StandardErrorPath and fix ownership/permissions","Reinstall the service so the log directory and files are recreated with correct modes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// re-check immediately before following\nif !log_file.exists() || log_file.metadata().map(|m| m.is_file()).unwrap_or(false) == false {\n    // refresh: pick the newest *.log in the dir or tell the user to reinstall\n}","typeGuard":null,"tryCatchPattern":"match service::logs(&config, InitSystem::Auto, lines, true) {\n    Err(err) if err.to_string().contains(\"tail exited with non-zero status\") => {\n        // likely rotation or permissions: report and retry once without follow\n        let _ = service::logs(&config, InitSystem::Auto, lines, false);\n    }\n    result => result?,\n}","preventionTips":["Handle log rotation so followed files are recreated atomically","Verify read permissions on the log dir after install","Ensure PATH contains coreutils in the environment that runs service logs"],"tags":["macos","logs","tail","follow","subprocess"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}