{"record":{"id":"fb5563a397aad6eb","repo":"elkowar/eww","slug":"the-script-for-the-variable-exited-unsuccessf","errorCode":null,"errorMessage":"The script for the `{}`-variable exited unsuccessfully","messagePattern":"The script for the `(.+?)`-variable exited unsuccessfully","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eww/src/config/script_var.rs","lineNumber":31,"sourceCode":"pub fn create_script_var_failed_warn(span: Span, var_name: &VarName, error_output: &str) -> DiagError {\n    DiagError(gen_diagnostic! {\n        kind = Severity::Warning,\n        msg = format!(\"The script for the `{}`-variable exited unsuccessfully\", var_name),\n        label = span => \"Defined here\",\n        note = error_output,\n    })\n}\n\npub fn initial_value(var: &ScriptVarDefinition) -> Result<DynVal> {\n    match var {\n        ScriptVarDefinition::Poll(x) => match &x.initial_value {\n            Some(value) => Ok(value.clone()),\n            None => match &x.command {\n                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))","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/elkowar/eww/blob/48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa/crates/eww/src/config/script_var.rs#L13-L49","documentation":"initial_value computes the first value of a script variable. For a `VarSource::Shell` (a shell command from `:command`), the command is run once synchronously; if it exits non-zero, eww wraps the failure warning in this error saying the script for the variable exited unsuccessfully.","triggerScenarios":"Defining a polled/initial script var whose `:command` shell string fails on first evaluation — command not found, non-zero exit, bad syntax — when the initial value is computed.","commonSituations":"Command depends on a tool not installed; script fails on a fresh machine before dependencies exist; quoting errors in the yuck command string; command exits non-zero under eww's environment.","solutions":["Run the :command string manually in a shell and fix whatever makes it exit non-zero","Make the script exit 0 even on failure (e.g. append `|| echo 'fallback'` or `2>/dev/null || true`)","Install missing dependencies the script relies on"],"exampleFix":"; before\n(defpoll cpu :interval \"1s\" \"mpstat 1 1 | awk '/Average/{print $3}'\")  ; mpstat not installed\n\n; after\n(defpoll cpu :interval \"1s\" \"command -v mpstat >/dev/null && mpstat 1 1 | awk '/Average/{print $3}' || echo 0\")","handlingStrategy":"try-catch","validationCode":"// shell: verify the command succeeds before configuring it\nmycommand || echo \"fix: exits $?, would break initial value\"","typeGuard":null,"tryCatchPattern":"match script_var::initial_value(&var) {\n    Ok(v) => /* use v */,\n    Err(e) => log::warn!(\"using default for {}: {e:#}\", var.name()),\n}","preventionTips":["Test every :command manually first","Always end poll scripts with a guaranteed exit 0 fallback","Install dependencies before deploying the config"],"tags":["eww","script-var","shell-command","exit-code"],"backgroundTag":"command-not-found","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"}