{"record":{"id":"78cefdc699fcbc90","repo":"jdx/mise","slug":"edits-reason-fix-the-file-manually","errorCode":null,"errorMessage":"edits: \"{}\": {reason}, fix the file manually","messagePattern":"edits: \"(.+?)\": (.+?), fix the file manually","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/edits.rs","lineNumber":1050,"sourceCode":"        \"edits: unapplied {}\",\n        todo.iter()\n            .map(|plan| format!(\"{} ({})\", plan.req.path_raw, plan.req.describe_op()))\n            .collect::<Vec<_>>()\n            .join(\", \")\n    );\n    Ok(())\n}\n\nfn unapply_one(req: &EditRequest) -> Result<()> {\n    let text = file::read_to_string(&req.path)?;\n    let lines = text_lines(&text);\n    let remove = match &req.op {\n        EditOp::Block { comment, .. } => {\n            let refs = lines.iter().map(|line| line.content).collect::<Vec<_>>();\n            match find_block(&refs, &req.id, comment) {\n                Ok(Some((begin, end))) => lines[begin].start..lines[end].end,\n                Ok(None) => return Ok(()),\n                Err(reason) => bail!(\n                    \"edits: \\\"{}\\\": {reason}, fix the file manually\",\n                    req.path_raw\n                ),\n            }\n        }\n        EditOp::Line { line, position } => {\n            // Use the occurrence nearest the configured insertion edge as the\n            // best stateless approximation of the line mise added.\n            let found = match position {\n                LinePosition::Prepend => lines.iter().find(|candidate| candidate.content == line),\n                LinePosition::Append => lines.iter().rfind(|candidate| candidate.content == line),\n            };\n            if let Some(found) = found {\n                found.start..found.end\n            } else {\n                return Ok(());\n            }\n        }","sourceCodeStart":1032,"sourceCodeEnd":1068,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/edits.rs#L1032-L1068","documentation":"Thrown in `unapply_one` (invoked from execute_unapply) when removing a Block edit: `find_block` fails to locate a well-formed managed block in the file (e.g. opening marker without a closing marker, mismatched id, or nested/mangled markers). Because removing half of a broken block could destroy user content, the operation refuses and asks the user to fix the file manually.","triggerScenarios":"Unapplying an `EditOp::Block` entry whose comment markers in the target file are missing, malformed, unbalanced, or belong to a different block id — find_block returns Err(reason) instead of Ok(Some(range)) or Ok(None).","commonSituations":"User manually deleted the closing marker of a managed block; a formatter reflowed comment markers; block ids were renamed in the config so the file's markers no longer match; partial application was interrupted leaving a half-written block.","solutions":["Open the file named in the error and repair the managed block markers so they are balanced and carry the expected id.","If the block content is no longer wanted, delete the whole block (markers and body) manually.","Re-run the unapply; a correctly removed block will make find_block return None and unapply proceeds.","If markers changed style (e.g. different comment syntax), restore the exact original style the tool wrote."],"exampleFix":"// before: dangling marker (no close)\n# >>> managed block id=exports\nexport FOO=1\n// after: delete entire block or add closing marker\n# >>> managed block id=exports\nexport FOO=1\n# <<< managed block id=exports","handlingStrategy":"validation","validationCode":"fn block_markers_balanced(text: &str, id: &str) -> bool {\n    let open = format!(\">>> managed block id={}\", id);\n    let close = format!(\"<<< managed block id={}\", id);\n    text.matches(&open).count() == 1 && text.matches(&close).count() == 1\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"fix the file manually\") => {\n        // open the named file, repair/remove the broken block, then retry\n    }\n    other => other?,\n}","preventionTips":["Always delete managed blocks with the tool, not by hand.","Restore both markers whenever editing near a block.","Keep ids unique across entries so markers cannot be confused."],"tags":["file-editing","markers","manual-fix"],"backgroundTag":"file-not-found","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"}