{"record":{"id":"622cedfd8d8d0c60","repo":"jdx/mise","slug":"failed-to-add","errorCode":null,"errorMessage":"failed to add {}","messagePattern":"failed to add (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/dotfiles/edit.rs","lineNumber":97,"sourceCode":"        DotfilesAdd {\n            targets: vec![self.target.clone()],\n            changed: false,\n            mode: self.mode.clone(),\n            source: self.source.clone(),\n            global: true,\n            local: false,\n            path: None,\n            dry_run: false,\n            no_apply: true,\n            force: false,\n            yes: true,\n        }\n        .run()\n        .await?;\n\n        config = Config::reset().await?;\n        let Some(path) = source_for_target(&config, &target, &self.target)? else {\n            bail!(\"failed to add {}\", self.target);\n        };\n        open_or_create(&path)?;\n        crate::cli::editor::open_in_editor(&path)?;\n        if self.apply {\n            apply_target(&self.target).await?;\n        }\n        Ok(())\n    }\n}\n\nfn source_for_target(\n    config: &Config,\n    target: &std::path::Path,\n    raw: &str,\n) -> Result<Option<PathBuf>> {\n    for req in system::files::files_from_config(config)? {\n        if system::files::matches_target(&req.target, &req.target_raw, &[raw.to_string()]) {\n            return Ok(Some(req.source));","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/cli/dotfiles/edit.rs#L79-L115","documentation":"`mise bootstrap dotfiles edit <TARGET>` opens the managed source for a dotfile. If the target is not yet managed, the command first runs an implicit `dotfiles add` for it, reloads the config, and re-resolves the target's source. When even after that successful-looking add the source still cannot be resolved, mise throws \"failed to add <target>\" because the internal invariant 'after add, the target must be resolvable' was violated.","triggerScenarios":"Running `mise bootstrap dotfiles edit <target>` where the target is unmanaged, the implicit `DotfilesAdd` run reports success but `source_for_target` still returns None afterwards (e.g. the add wrote to a config file that does not actually register the target, or the target string resolves to a different path on re-resolution).","commonSituations":"Adding a dotfile whose config entry lands in a file that is later overridden by another config layer; typos or symlinks that make the resolved target differ between the add and the re-lookup; concurrent modification of the global config during the edit command.","solutions":["Run `mise bootstrap dotfiles add <target>` explicitly and inspect its output to see why the entry is not registered.","Check the global config ([dotfiles] section) for an entry for the target after the failed run; if missing, add it manually.","Re-run the edit with `--yes` and an explicit `--source`/`--mode` so the implicit add has full information.","Report the case as a bug if add succeeds but the target still does not resolve — this is an internal invariant violation."],"exampleFix":"// before (shell)\nmise bootstrap dotfiles edit ~/.zshrc   # failed to add ~/.zshrc\n// after\nmise bootstrap dotfiles add ~/.zshrc --yes\nmise bootstrap dotfiles edit ~/.zshrc","handlingStrategy":"validation","validationCode":"# resolve the managed source before opening an editor\nif ! mise bootstrap dotfiles paths | grep -qx \"$target\"; then\n  mise bootstrap dotfiles add \"$target\" --yes || exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Explicitly run `dotfiles add` instead of relying on the implicit add inside `edit`.","Verify with `dotfiles paths` that the target is managed before editing."],"tags":["dotfiles","cli","internal-invariant"],"backgroundTag":"resource-not-found","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}