{"record":{"id":"ba9512ba5dcbd19f","repo":"jdx/mise","slug":"querying-scheduled-task-task-failed","errorCode":null,"errorMessage":"querying scheduled task {task} failed: {}","messagePattern":"querying scheduled task (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/scheduled_tasks.rs","lineNumber":492,"sourceCode":"    }\n    let args = [\n        \"-NoProfile\".to_string(),\n        \"-NonInteractive\".to_string(),\n        \"-Command\".to_string(),\n        query_script(name),\n    ];\n    debug!(\"$ powershell {}\", shell_words::join(&args));\n    let mut cmd = tokio::process::Command::new(\"powershell.exe\");\n    cmd.args(&args)\n        .stdin(Stdio::null())\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped())\n        .kill_on_drop(true);\n    let output = tokio::time::timeout(SCHTASKS_TIMEOUT, cmd.output())\n        .await\n        .map_err(|_| eyre!(\"querying scheduled task {task} timed out\"))??;\n    if !output.status.success() {\n        bail!(\n            \"querying scheduled task {task} failed: {}\",\n            String::from_utf8_lossy(&output.stderr).trim()\n        );\n    }\n    Ok(parse_query(&String::from_utf8_lossy(&output.stdout)))\n}\n\nfn parse_query(output: &str) -> Option<Query> {\n    let state = output.trim();\n    if state.eq_ignore_ascii_case(\"MISSING\") || state.is_empty() {\n        return None;\n    }\n    Some(Query {\n        running: state.eq_ignore_ascii_case(\"Running\"),\n        disabled: state.eq_ignore_ascii_case(\"Disabled\"),\n    })\n}\n","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/scheduled_tasks.rs#L474-L510","documentation":"After running the schtasks query, mise checks the exit status; a non-zero status makes mise surface schtasks' stderr verbatim as this error. It wraps the underlying Windows Task Scheduler failure — typically 'the system cannot find the file specified' when the task does not exist, or access/timeout problems.","triggerScenarios":"query() in scheduled_tasks.rs runs schtasks and the process exits non-zero: the task name does not exist, the user lacks permission to read the task, the Task Scheduler service is unavailable, or the command printed an error to stderr.","commonSituations":"Checking status of a scheduled task before it was ever created (apply never ran), running without the privileges needed to read tasks in another folder or created by another user, or schtasks failing due to a transient system condition.","solutions":["Check the embedded stderr message: if it says the task does not exist, run the task's apply/create first or treat 'not found' as expected","Run the terminal elevated (or as the same user that created the task) if access was denied","Verify the Task Scheduler service is running and retry; note the separate timeout error exists for hangs","Run `schtasks /query /tn <name>` manually to reproduce and see the raw error"],"exampleFix":"// before\nlet running = task_exists(\"Mise\\\\deploy-hook\").await?;\n// after\nlet running = match task_exists(\"Mise\\\\deploy-hook\").await {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"cannot find\") => false,\n    Err(e) => return Err(e),\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match mise_scheduled_task_status(name) {\n    Ok(status) => status,\n    Err(e) if e.to_string().to_lowercase().contains(\"cannot find\") => Status::Missing,\n    Err(e) => return Err(e),\n}","preventionTips":["Treat 'task not found' stderr as an expected state, not a hard failure","Ensure the same user/elevation level created and queries the task","Run apply before querying newly configured tasks","Verify the Task Scheduler service is healthy on the machine"],"tags":["windows","schtasks","process-exit","scheduled-tasks"],"backgroundTag":"command-not-found","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}