{"record":{"id":"5815bd0b9aef51ea","repo":"elkowar/eww","slug":"failed-with-output","errorCode":null,"errorMessage":"Failed with output:\n{}","messagePattern":"Failed with output:\n(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eww/src/config/script_var.rs","lineNumber":45,"sourceCode":"                VarSource::Function(f) => f()\n                    .map_err(|err| anyhow!(err))\n                    .with_context(|| format!(\"Failed to compute initial value for {}\", &var.name())),\n                VarSource::Shell(span, command) => {\n                    run_command(command).map_err(|e| anyhow!(create_script_var_failed_warn(*span, var.name(), &e.to_string())))\n                }\n            },\n        },\n\n        ScriptVarDefinition::Listen(var) => Ok(var.initial_value.clone()),\n    }\n}\n\n/// Run a command and get the output\npub fn run_command(cmd: &str) -> Result<DynVal> {\n    log::debug!(\"Running command: {}\", cmd);\n    let command = Command::new(\"/bin/sh\").arg(\"-c\").arg(cmd).output()?;\n    if !command.status.success() {\n        bail!(\"Failed with output:\\n{}\", String::from_utf8(command.stderr)?);\n    }\n    let output = String::from_utf8(command.stdout)?;\n    let output = output.trim_matches('\\n');\n    Ok(DynVal::from(output))\n}\n","sourceCodeStart":27,"sourceCodeEnd":51,"githubUrl":"https://github.com/elkowar/eww/blob/48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa/crates/eww/src/config/script_var.rs#L27-L51","documentation":"script_var::run_command executes a script- variable's command through /bin/sh -c and captures its output. If the command exits with a non-zero status, eww bails with the command's stderr. This surfaces user script failures as eww variable errors.","triggerScenarios":"Defining a script var (e.g. `:interval` polled `:script \"...\"`) whose shell command returns a non-zero exit code; the error text contains whatever the script wrote to stderr.","commonSituations":"Scripts referencing missing binaries or files; scripts failing intermittently (network calls, sensors); quoting bugs in the :script attribute; scripts that print to stderr but also exit non-zero on transient conditions.","solutions":["Run the exact script command in a shell and fix why it exits non-zero","Make the script handle transient errors and `exit 0` with a sensible fallback value","Check stderr in the error message — it contains the actual failure output","Ensure all binaries the script calls are installed and on PATH for the eww daemon's environment"],"exampleFix":"// before (script var)\n(defpoll battery :interval \"10s\" :script \"cat /sys/class/power_supply/BAT0/capacity\")\n// after\n(defpoll battery :interval \"10s\" :script \"cat /sys/class/power_supply/BAT0/capacity 2>/dev/null || echo 0\")","handlingStrategy":"try-catch","validationCode":"// Test the script manually first:\n// /bin/sh -c '<your :script command>' && echo OK || echo FAILS\nconst { status } = cp.spawnSync('/bin/sh', ['-c', script]);\nif (status !== 0) throw new Error(`script var would fail (exit ${status})`);","typeGuard":null,"tryCatchPattern":"match run_command(cmd) {\n    Ok(v) => v,\n    Err(e) => { log::warn!(\"script var failed: {e}\"); DynVal::from(fallback_value) }\n}","preventionTips":["Exit 0 with a fallback value instead of failing on transient errors","Test every :script command in a shell before adding it to the config","Ensure all binaries used by scripts are installed and on the daemon's PATH","Redirect diagnostics to stderr and keep exit codes meaningful"],"tags":["shell","script-var","subprocess","stderr"],"backgroundTag":"command-failed","analyzedSha":"48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa","analyzedAt":"2026-09-08T03:13:26.897Z","contentChangedAt":"2026-09-08T03:13:26.897Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}