{"record":{"id":"6c4a8724390c04a1","repo":"jdx/mise","slug":"watch-files-command-failed-status","errorCode":null,"errorMessage":"watch_files command failed: {status}","messagePattern":"watch_files command failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/watch_files.rs","lineNumber":128,"sourceCode":"        \"MISE_PROJECT_ROOT\".to_string(),\n        root.to_string_lossy().to_string(),\n    );\n    // TODO: this should be different but I don't have easy access to it\n    // env.insert(\"MISE_CONFIG_ROOT\".to_string(), root.to_string_lossy().to_string());\n    // On Windows, `cmd /c <run>` must receive the command verbatim so inner\n    // double quotes survive (#9355). Mirror the hook path: spawn a raw Command\n    // with stdout redirected to our stderr handle (duct's stdout_to_stderr) and\n    // the full env. Non-cmd shells / Unix fall through to the duct path below.\n    #[cfg(windows)]\n    {\n        if let Some(mut c) = crate::path::cmd_verbatim_command(program, shell_args, run) {\n            use std::os::windows::io::AsHandle;\n            c.env_clear();\n            c.envs(env.iter());\n            c.stdout(std::io::stderr().as_handle().try_clone_to_owned()?);\n            let status = c.status()?;\n            if !status.success() {\n                eyre::bail!(\"watch_files command failed: {status}\");\n            }\n            return Ok(());\n        }\n    }\n    crate::inline_command::optimize_expression(\n        cmd(program, args).full_env(&env),\n        run,\n        &env,\n        None,\n        direct_enabled,\n    )\n    .stdout_to_stderr()\n    .run()?;\n    Ok(())\n}\n\nasync fn execute_task(\n    config: &Arc<Config>,","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/watch_files.rs#L110-L146","documentation":"watch_files::execute runs the file-watcher command and bails when the child process exits with a non-success status. On Windows it runs the command with a scrubbed environment capturing stdout to stderr; any nonzero exit of the watch command produces this error with the platform's ExitStatus rendering.","triggerScenarios":"The command mise watches files with (e.g. a task's watch command or a watcher binary) exits nonzero — the watcher crashed, the watched command failed, or the env required by the watcher was cleared.","commonSituations":"A watch task wrapping a build that fails on change (syntax error), the watcher binary missing required environment variables after env_clear, or Ctrl-C/abnormal termination of the watcher being treated as a failed status.","solutions":["Fix the underlying command that failed — run it directly (outside watch mode) and address its own error output.","Verify the watcher binary/dependency exists and runs on this platform, especially on Windows where the code path differs.","Check that the task doesn't depend on environment variables removed by the Windows env_clear branch; set them via mise [env] config.","Re-run mise watch after fixing; if it persists, capture stderr (which the command's stdout is redirected to) for the watcher's own message."],"exampleFix":"// before (task failing under watch)\n[task.dev]\nrun = \"node build.js\"\n// after — fix the failing build command first\n[task.dev]\nrun = \"node build.js\"\n# then: mise watch task dev","handlingStrategy":"try-catch","validationCode":"// Verify the watch command exits 0 before enabling watch mode:\nconst probe = run(cmd, args); if (probe.status !== 0) throw new Error(`watch cmd fails standalone: ${probe.stderr}`);","typeGuard":null,"tryCatchPattern":"try {\n  run('mise watch', ['task', 'dev']);\n} catch (e) {\n  if (/watch_files command failed/.test(String(e))) {\n    console.error('watched command failed; run it directly to see the real error');\n    run(cmd, args); // surface the underlying failure\n  } else throw e;\n}","preventionTips":["Run the underlying task directly first; only enable watch mode once it succeeds.","Ensure required env vars come from mise [env] so they survive environment scrubbing.","Keep watcher binaries and dependencies installed on every platform you develop on, including Windows."],"tags":["process-exit","watch","windows","task-execution"],"backgroundTag":"command-not-found","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}