elkowar/eww · error

Failed with output

Error message

Failed with output:
{}

What it means

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.

Solutions

  1. Run the exact script command in a shell and fix why it exits non-zero
  2. Make the script handle transient errors and `exit 0` with a sensible fallback value
  3. Check stderr in the error message — it contains the actual failure output
  4. Ensure all binaries the script calls are installed and on PATH for the eww daemon's environment

Example fix

// before (script var)
(defpoll battery :interval "10s" :script "cat /sys/class/power_supply/BAT0/capacity")
// after
(defpoll battery :interval "10s" :script "cat /sys/class/power_supply/BAT0/capacity 2>/dev/null || echo 0")
Defensive patterns

Strategy: try-catch

Validate before calling

// Test the script manually first:
// /bin/sh -c '<your :script command>' && echo OK || echo FAILS
const { status } = cp.spawnSync('/bin/sh', ['-c', script]);
if (status !== 0) throw new Error(`script var would fail (exit ${status})`);

Try / catch

match run_command(cmd) {
    Ok(v) => v,
    Err(e) => { log::warn!("script var failed: {e}"); DynVal::from(fallback_value) }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of elkowar/eww@48f5aa8b37 (2026-09-08). Data as JSON: /api/errors/5815bd0b9aef51ea. Report an issue: GitHub.

Appendix: source

Thrown at crates/eww/src/config/script_var.rs:45

                VarSource::Function(f) => f()
                    .map_err(|err| anyhow!(err))
                    .with_context(|| format!("Failed to compute initial value for {}", &var.name())),
                VarSource::Shell(span, command) => {
                    run_command(command).map_err(|e| anyhow!(create_script_var_failed_warn(*span, var.name(), &e.to_string())))
                }
            },
        },

        ScriptVarDefinition::Listen(var) => Ok(var.initial_value.clone()),
    }
}

/// Run a command and get the output
pub fn run_command(cmd: &str) -> Result<DynVal> {
    log::debug!("Running command: {}", cmd);
    let command = Command::new("/bin/sh").arg("-c").arg(cmd).output()?;
    if !command.status.success() {
        bail!("Failed with output:\n{}", String::from_utf8(command.stderr)?);
    }
    let output = String::from_utf8(command.stdout)?;
    let output = output.trim_matches('\n');
    Ok(DynVal::from(output))
}

View on GitHub (pinned to 48f5aa8b37)