{"record":{"id":"41e0edc8618ed706","repo":"jdx/mise","slug":"cannot-use-task-syntax-without-a-current-working","errorCode":null,"errorMessage":"Cannot use :task syntax without a current working directory","messagePattern":"Cannot use :task syntax without a current working directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task/task_load_context.rs","lineNumber":254,"sourceCode":"        if let Some(scope) = monorepo_scope(&monorepo_root, scope_dir) {\n            // For bare task names, only expand if we're actually in the monorepo\n            // For colon patterns, always expand (and error if outside monorepo)\n\n            if is_colon_pattern {\n                Ok(format!(\"{scope}{task}\"))\n            } else {\n                Ok(format!(\"{scope}:{task}\"))\n            }\n        } else {\n            if is_colon_pattern {\n                bail!(\"Cannot use :task syntax outside of monorepo root directory\");\n            }\n            // Bare name outside monorepo - return as-is for global matching\n            Ok(task.to_string())\n        }\n    } else {\n        if is_colon_pattern {\n            bail!(\"Cannot use :task syntax without a current working directory\");\n        }\n        Ok(task.to_string())\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_monorepo_scope() {\n        let root = Path::new(\"repo\");\n        assert_eq!(monorepo_scope(root, root), Some(\"//\".to_string()));\n        assert_eq!(\n            monorepo_scope(root, &root.join(\"apps\").join(\"api\")),\n            Some(\"//apps/api\".to_string())\n        );\n        assert_eq!(monorepo_scope(root, Path::new(\"other\")), None);","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/jdx/mise/blob/9dcfcaa0dc8747a2577d3270b69bb9d8313b2807/src/task/task_load_context.rs#L236-L272","documentation":"Companion guard to 968: when expanding a colon pattern, mise needs the current working directory to compute the monorepo scope; if dirs::CWD is None (process has no resolvable cwd), it cannot expand ':' patterns and bails. Bare names are returned as-is for global matching.","triggerScenarios":"mise runs in a process whose cwd has been deleted or is inaccessible (cwd unlinked while the shell/process still runs), or a host environment that fails to report a working directory. Only fires for ':'-prefixed task arguments.","commonSituations":"Deleting the directory a long-running shell sits in and then running mise; container/sandbox runtimes with broken cwd; exotic init systems spawning mise without a valid cwd.","solutions":["cd to an existing directory (`cd ~/repo`) to refresh the process cwd, then retry.","Reopen the terminal / restart the container if the shell's cwd is gone.","Use absolute task syntax `mise //pkg:build`, which skips cwd-based expansion entirely.","Avoid deleting the directory your shell is currently in."],"exampleFix":"# before (cwd was deleted)\n$ mise :build\nerror: Cannot use :task syntax without a current working directory\n\n# after\n$ cd ~/repo && mise :build","handlingStrategy":"fallback","validationCode":"# verify cwd exists before colon-pattern tasks\n[ -d \"$(pwd -P 2>/dev/null)\" ] || { echo 'cwd invalid; cd somewhere' >&2; exit 1; }\nmise :build","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't delete the directory your shell is in; cd away first.","Restart shells/containers with broken cwd.","Use //pkg:task which is cwd-independent."],"tags":["monorepo","working-directory","environment","mise"],"backgroundTag":"monorepo-scope-resolution-failed","analyzedSha":"9dcfcaa0dc8747a2577d3270b69bb9d8313b2807","analyzedAt":"2026-08-17T14:28:50.624Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}