jdx/mise · error

scheduled task name {name:?} contains characters that cannot

Error message

scheduled task name {name:?} contains characters that cannot be queried

What it means

The query helper strips an optional 'mise\' prefix and then validates that the remaining task name consists only of ASCII alphanumerics, '.', '_', or '-'. Names containing anything else (spaces, backslashes, shell metacharacters) cannot be safely passed to the PowerShell query script, so query refuses them before spawning a process.

Source

Thrown at src/system/scheduled_tasks.rs:457

/// The task's state through the Task Scheduler API rather than the
/// localized text `schtasks /query` prints. Prints `MISSING` for an
/// unregistered task and the `TaskState` name otherwise. The name is
/// embedded in the script (arguments after `-Command` are more command
/// text, not `$args`); names are validated to letters, digits, `.`, `_`,
/// and `-` before they get here.
fn query_script(name: &str) -> String {
    format!(
        "$t = Get-ScheduledTask -TaskPath '\\mise\\' -TaskName '{name}' -ErrorAction SilentlyContinue; if ($null -eq $t) {{ 'MISSING' }} else {{ $t.State.ToString() }}"
    )
}

async fn query(task: &str) -> Result<Option<Query>> {
    let name = task.strip_prefix("mise\\").unwrap_or(task);
    if !name
        .chars()
        .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'))
    {
        bail!("scheduled task name {name:?} contains characters that cannot be queried");
    }
    let args = [
        "-NoProfile".to_string(),
        "-NonInteractive".to_string(),
        "-Command".to_string(),
        query_script(name),
    ];
    debug!("$ powershell {}", shell_words::join(&args));
    let mut cmd = tokio::process::Command::new("powershell.exe");
    cmd.args(&args)
        .stdin(Stdio::null())
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .kill_on_drop(true);
    let output = tokio::time::timeout(SCHTASKS_TIMEOUT, cmd.output())
        .await
        .map_err(|_| eyre!("querying scheduled task {task} timed out"))??;
    if !output.status.success() {

View on GitHub (pinned to afd2eddd3a)

Solutions

  1. Rename the task/service so its name uses only letters, digits, '.', '_', '-' (and rely on the 'mise\\' folder prefix for namespacing).
  2. Strip any path/folder components before calling, keeping only the bare task name.
  3. Quote/normalize user-supplied service names at a higher layer before they reach the task API.
  4. If you control the name source (config), add a validation rule matching [A-Za-z0-9._-]+ there.

Example fix

// before
exists("mise\\My Service")?; // space is not queryable
// after
exists("mise\\my-service")?;
Defensive patterns

Strategy: validation

Validate before calling

fn valid_task_name(name: &str) -> Result<(), String> {
    let bare = name.strip_prefix("mise\\").unwrap_or(name);
    if !bare.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-')) {
        return Err(format!("task name {bare:?} must match [A-Za-z0-9._-]+"));
    }
    Ok(())
}

Type guard

fn is_queryable_task_name(task: &str) -> bool {
    let bare = task.strip_prefix("mise\\").unwrap_or(task);
    !bare.is_empty()
        && bare.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'))
}

Prevention

When it happens

Trigger: Calling status, exists, or apply with a task string whose name (after stripping the 'mise\' prefix) contains characters outside [A-Za-z0-9._-] — e.g. spaces, '\', '/', ':', quotes.

Common situations: Passing a full path like 'C:\tasks\my task' instead of just the task name; names with spaces copied from Task Scheduler; accidentally passing a command or extra arguments in the task string; non-ASCII characters in service names.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of jdx/mise@afd2eddd3a (2026-09-09). Data as JSON: /api/errors/31f675e30807d098. Report an issue: GitHub.