{"record":{"id":"82f89d7edf338354","repo":"Hmbown/CodeWhale","slug":"edit-refused-it-would-leave-display-path-unparseable-issue","errorCode":null,"errorMessage":"Edit refused: it would leave {display_path} unparseable — {issue}. Nothing was written; the file is unchanged. Recovery: re-read the file with File action=\"read\", check the replacement for unbalanced delimiters or a truncated block, and retry.","messagePattern":"Edit refused: it would leave (.+?) unparseable — (.+?)\\. Nothing was written; the file is unchanged\\. Recovery: re-read the file with File action=\"read\", check the replacement for unbalanced delimiters or a truncated block, and retry\\.","errorType":"validation","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/syntax_check.rs","lineNumber":160,"sourceCode":"    };\n    // Fail open on a file that was already broken (or is brand new): the gate\n    // exists to catch the edit that *introduces* a syntax error, never to\n    // strand a model that is repairing one.\n    let Some(before) = before else {\n        return Ok(());\n    };\n    if syntax_check(path, before).is_some() {\n        return Ok(());\n    }\n    Err(ToolError::execution_failed(format!(\n        \"Edit refused: it would leave {display_path} unparseable — {issue}. Nothing was written; \\\n         the file is unchanged. Recovery: re-read the file with File action=\\\"read\\\", check the \\\n         replacement for unbalanced delimiters or a truncated block, and retry.\"\n    )))\n}\n\nfn check_rust(source: &str) -> Option<SyntaxIssue> {\n    let error = syn::parse_file(source).err()?;\n    // A `syn::Error` can carry several diagnostics; the first is the earliest\n    // and the one worth showing.\n    let first = error.into_iter().next()?;\n    let start = first.span().start();\n    Some(SyntaxIssue {\n        language: SyntaxLanguage::Rust,\n        line: start.line,\n        // `proc-macro2` columns are 0-based; editors and rustc are not.\n        column: start.column.saturating_add(1),\n        message: first.to_string(),\n    })\n}\n\nfn check_toml(source: &str) -> Option<SyntaxIssue> {\n    let error = source.parse::<toml_edit::DocumentMut>().err()?;\n    let (line, column) = error\n        .span()\n        .map_or((1, 1), |span| line_column(source, span.start));","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/syntax_check.rs#L142-L178","documentation":"The edit tool's syntax guard parsed the post-edit content of a .rs file with `syn::parse_file` and it failed, so the write was refused. The gate only fires when the file was parseable BEFORE the edit, guaranteeing the proposed edit is what breaks the file. Nothing was written to disk.","triggerScenarios":"Calling the File edit action on a Rust file whose resulting content fails `syn::parse_file` (rust file was valid before, would not parse after). check_rust reports the first syn diagnostic with 1-based line/column.","commonSituations":"A model/agent replacement block is truncated mid-function; unbalanced braces from a partial replace; a replacement string accidentally containing invalid token sequences; edit anchors spanning half of a match arm.","solutions":["Re-read the file with File action=\"read\" to get its unchanged, valid content.","Locate the reported line/column and compare your replacement against the original block.","Fix unbalanced braces/parens or the truncated block and retry the edit.","Split a large risky edit into smaller syntactically complete chunks."],"exampleFix":"// before (truncated replacement leaves brace unbalanced)\nfn f() {\n    let x = 1;\n// after (complete block)\nfn f() {\n    let x = 1;\n}","handlingStrategy":"validation","validationCode":"// validate the post-edit Rust content before calling the edit tool\nif syn::parse_file(&after_content).is_err() {\n    // fix braces/truncated block first; the edit would be refused\n}","typeGuard":null,"tryCatchPattern":"// caller of the edit tool: on refusal, re-read and retry\nmatch tool.edit(path, old, new) {\n    Err(e) if e.to_string().contains(\"Edit refused: it would leave\") => {\n        let fresh = tool.read(path)?; // file is byte-for-byte unchanged\n        // diagnose reported line/column and retry with corrected replacement\n    }\n    other => other?,\n}","preventionTips":["Always re-read the file before constructing a replacement.","Keep replacements syntactically complete — never truncate mid-block.","Prefer narrow, single-construct edits over file-spanning replaces.","Run rustfmt or `rustc --emit=metadata` on the snippet mentally/locally before applying."],"tags":["rust","syntax","edit-guard","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}