jdx/mise · error

Cannot use :task syntax without a current working directory

Error message

Cannot use :task syntax without a current working directory

What it means

expand_colon_task_syntax needs the current working directory to compute the monorepo package scope for ':task' references. When the process has no current working directory (deleted CWD, or unavailable path), any colon-prefixed reference cannot be scoped and is rejected; bare names still resolve.

Solutions

  1. cd to a valid existing directory and re-run
  2. Restore/recreate the deleted directory your shell was in
  3. Restart the shell to reset its CWD
  4. Avoid ':'-prefixed task refs; use the full '//pkg:task' form or a bare task name

Example fix

// before (shell cwd deleted)
mise run :build
// after
cd /path/to/repo/packages/api
mise run :build
Defensive patterns

Strategy: validation

Validate before calling

CWD=$(pwd) || { echo 'current directory unavailable'; exit 1; }

Try / catch

if ! CWD=$(pwd) 2>/dev/null; then echo 'cwd deleted; cd to a valid dir' >&2; exit 1; fi; mise run :task

Prevention

When it happens

Trigger: Running `mise run :task` when std::env::current_dir() fails — typically because the shell's current directory was deleted, or in exotic sandboxes where CWD is unavailable.

Common situations: A terminal left in a directory removed by a build cleanup or git operation; container/CI steps that rm the working directory before invoking mise; running from a mount that was unmounted.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/41e0edc8618ed706. Report an issue: GitHub.

Appendix: source

Thrown at src/task/task_load_context.rs:254

        if let Some(scope) = monorepo_scope(&monorepo_root, scope_dir) {
            // For bare task names, only expand if we're actually in the monorepo
            // For colon patterns, always expand (and error if outside monorepo)

            if is_colon_pattern {
                Ok(format!("{scope}{task}"))
            } else {
                Ok(format!("{scope}:{task}"))
            }
        } else {
            if is_colon_pattern {
                bail!("Cannot use :task syntax outside of monorepo root directory");
            }
            // Bare name outside monorepo - return as-is for global matching
            Ok(task.to_string())
        }
    } else {
        if is_colon_pattern {
            bail!("Cannot use :task syntax without a current working directory");
        }
        Ok(task.to_string())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_monorepo_scope() {
        let root = Path::new("repo");
        assert_eq!(monorepo_scope(root, root), Some("//".to_string()));
        assert_eq!(
            monorepo_scope(root, &root.join("apps").join("api")),
            Some("//apps/api".to_string())
        );
        assert_eq!(monorepo_scope(root, Path::new("other")), None);

View on GitHub (pinned to 533346cc37)