{"record":{"id":"7ca8698865ff1e33","repo":"jdx/mise","slug":"recursive-shim-invocation-detected-for-bin-name","errorCode":null,"errorMessage":"recursive shim invocation detected for {bin_name}: {}","messagePattern":"recursive shim invocation detected for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/shims.rs","lineNumber":118,"sourceCode":"pub(crate) async fn handle_shim() -> Result<()> {\n    // TODO: instead, check if bin is in shims dir\n    let bin_name = *env::MISE_BIN_NAME;\n    if env::is_mise_binary(bin_name) || cfg!(test) {\n        return Ok(());\n    }\n    #[cfg(windows)]\n    {\n        let shim_path = invoked_shim_path();\n        if env::var_path(env::MISE_SHIM_PATH_ENV)\n            .as_ref()\n            .is_some_and(|previous| {\n                file::paths_eq(\n                    &file::canonicalize_or_self(previous),\n                    &file::canonicalize_or_self(&shim_path),\n                )\n            })\n        {\n            bail!(\n                \"recursive shim invocation detected for {bin_name}: {}\",\n                display_path(&shim_path)\n            );\n        }\n        *env::MISE_SHIM_PATH.write().unwrap() = Some(shim_path.clone());\n        env::set_var(env::MISE_SHIM_PATH_ENV, &shim_path);\n    }\n    let mut config = Config::get().await?;\n    let mut args = env::ARGS.read().unwrap().clone();\n    env::PREFER_OFFLINE.store(true, Ordering::Relaxed);\n    trace!(\"shim[{bin_name}] args: {}\", args.join(\" \"));\n    let (bin, ts, wrapper) = which_shim(&mut config, &env::MISE_BIN_NAME, &args).await?;\n    args[0] = bin.to_string_lossy().to_string();\n    if let Some(wrapper) = &wrapper {\n        args.splice(1..1, wrapper.args().iter().cloned());\n    }\n    env::set_var(\"__MISE_SHIM\", \"1\");\n    let exec = Exec {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/shims.rs#L100-L136","documentation":"`handle_shim` records the current shim path in `MISE_SHIM_PATH` and detects when a shim resolves to a binary that is itself the same shim (via canonicalized path comparison of previous invocation and current shim path). When recursion is detected, mise bails instead of looping forever or overflowing the stack.","triggerScenarios":"A shim whose target binary is (or resolves to) the shim itself — e.g. a broken symlink loop, a tool binary overwritten by a copy of the shim, or `~/.local/share/mise/shims` duplicated on PATH so a tool name resolves back to mise's shim.","commonSituations":"Shims directory prepended twice in PATH within a deeply nested shell; an installed tool missing so PATH resolution falls through to the shim again; FS corruption or manual copying of shim files into a bin directory.","solutions":["Inspect PATH: `echo $PATH | tr ':' '\\n' | grep -n shims` and remove duplicate mise shims entries.","Reinstall the affected tool (`mise install <tool>@<version>`) so the real binary exists and the shim resolves correctly.","Delete and regenerate shims: `mise reshim` after fixing the tool install."],"exampleFix":"// before (.zshrc)\nexport PATH=\"$HOME/.local/share/mise/shims:$HOME/.local/share/mise/shims:$PATH\"\n// after\nexport PATH=\"$HOME/.local/share/mise/shims:$PATH\"","handlingStrategy":"try-catch","validationCode":"echo $PATH | tr ':' '\\n' | grep -c 'mise/shims'  # expect 1 occurrence","typeGuard":null,"tryCatchPattern":"try {\n  await $`${tool} --version`;\n} catch (e) {\n  if (String(e).includes('recursive shim invocation')) {\n    await $`mise reshim`;\n  } else throw e;\n}","preventionTips":["Keep mise's shims directory on PATH exactly once.","Run `mise reshim` after installing or removing tools.","Never copy shim files manually into bin directories."],"tags":["shims","recursion","path"],"backgroundTag":"internal-invariant-violation","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"}