{"record":{"id":"ce7c162622c30f05","repo":"FoundationAgents/OpenManus","slug":"no-replacement-was-performed-old-str-old-str","errorCode":null,"errorMessage":"No replacement was performed, old_str `{old_str}` did not appear verbatim in {path}.","messagePattern":"No replacement was performed, old_str `(.+?)` did not appear verbatim in (.+?)\\.","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"app/tool/str_replace_editor.py","lineNumber":300,"sourceCode":"        )\n\n    async def str_replace(\n        self,\n        path: PathLike,\n        old_str: str,\n        new_str: Optional[str] = None,\n        operator: FileOperator = None,\n    ) -> CLIResult:\n        \"\"\"Replace a unique string in a file with a new string.\"\"\"\n        # Read file content and expand tabs\n        file_content = (await operator.read_file(path)).expandtabs()\n        old_str = old_str.expandtabs()\n        new_str = new_str.expandtabs() if new_str is not None else \"\"\n\n        # Check if old_str is unique in the file\n        occurrences = file_content.count(old_str)\n        if occurrences == 0:\n            raise ToolError(\n                f\"No replacement was performed, old_str `{old_str}` did not appear verbatim in {path}.\"\n            )\n        elif occurrences > 1:\n            # Find line numbers of occurrences\n            file_content_lines = file_content.split(\"\\n\")\n            lines = [\n                idx + 1\n                for idx, line in enumerate(file_content_lines)\n                if old_str in line\n            ]\n            raise ToolError(\n                f\"No replacement was performed. Multiple occurrences of old_str `{old_str}` \"\n                f\"in lines {lines}. Please ensure it is unique\"\n            )\n\n        # Replace old_str with new_str\n        new_file_content = file_content.replace(old_str, new_str)\n","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/tool/str_replace_editor.py#L282-L318","documentation":"Thrown by the str_replace_editor tool when a str_replace operation finds zero occurrences of old_str in the target file. The tool reads the file, expands tabs on both content and arguments, and counts occurrences; an exact verbatim substring match is required before any edit is attempted. A zero count aborts the edit entirely — nothing is written.","triggerScenarios":"Calling str_replace with an old_str that does not exactly match file content: wrong indentation, tabs vs spaces (note tabs are expanded before matching, so an 8-space vs tab mismatch is normalized but other whitespace differences are not), trailing whitespace, line-ending differences (CRLF vs LF), or the file having changed since it was last read.","commonSituations":"Agent/tool pipelines that reuse a cached file snapshot then edit after another writer changed the file; copy-pasting old_str from a rendered view that altered whitespace; assuming fuzzy or regex matching when the tool only does literal substring matching.","solutions":["Re-read the file (view command) at the current path and copy old_str verbatim, including exact leading whitespace and line breaks.","Verify the path is correct — editing a different file than the one displayed is a frequent cause.","Check for line-ending or encoding mismatches; normalize the editor to LF if the file uses LF.","Use a longer, more distinctive snippet as old_str to guarantee an exact match.","If the string may have drifted, fall back to a write/insert operation instead of str_replace."],"exampleFix":"// before\nawait editor.str_replace('app/main.py', old_str='def run():\\n    pass', new_str='def run():\\n    return 0')  // indentation mismatch -> error\n// after\nawait editor.view('app/main.py')  // confirm exact text\nawait editor.str_replace('app/main.py', old_str='def run():\\n\\t pass', new_str='def run():\\n\\t return 0')  // copied verbatim from file","handlingStrategy":"validation","validationCode":"content = await operator.read_file(path)\nif old_str.expandtabs() not in content.expandtabs():\n    refreshed = await editor.view(path)  # re-read and re-derive old_str\n    # rebuild old_str from refreshed content or abort before calling str_replace","typeGuard":"def is_exact_snippet(content: str, old_str: str) -> bool:\n    return content.expandtabs().count(old_str.expandtabs()) == 1","tryCatchPattern":"try:\n    await editor.str_replace(path, old_str, new_str)\nexcept ToolError as e:\n    if 'did not appear verbatim' in str(e):\n        content = await editor.view(path)\n        # re-derive old_str from the fresh content and retry once\n    else:\n        raise","preventionTips":["Always view/read the file immediately before editing and copy old_str verbatim from that read.","Normalize line endings and tabs in your pipeline before constructing old_str (the tool expands tabs but nothing else).","Never build old_str from memory or a cached snapshot of the file."],"tags":["file-editing","str-replace","whitespace","agent-tools"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}