{"record":{"id":"213fa900bbe8bf31","repo":"Tencent/WeKnora","slug":"old-string-is-required-copy-the-exact-text-to-cha","errorCode":null,"errorMessage":"old_string is required; copy the exact text to change, including whitespace","messagePattern":"old_string is required; copy the exact text to change, including whitespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/sandbox_edit.go","lineNumber":278,"sourceCode":"\t\t\t\"path\":         clean,\n\t\t\t\"root\":         rootDir,\n\t\t\t\"name\":         path.Base(clean),\n\t\t\t\"size\":         len(content),\n\t\t\t\"replacements\": replacements,\n\t\t},\n\t}, nil\n}\n\n// Cleanup releases any resources.\nfunc (t *EditSandboxFileTool) Cleanup(ctx context.Context) error {\n\treturn nil\n}\n\n// applySandboxEdit performs an exact string replacement. replaceAll=false\n// requires a unique match.\nfunc applySandboxEdit(content, oldString, newString string, replaceAll bool) (string, int, error) {\n\tif oldString == \"\" {\n\t\treturn \"\", 0, fmt.Errorf(\"old_string is required; copy the exact text to change, including whitespace\")\n\t}\n\tif oldString == newString {\n\t\treturn \"\", 0, fmt.Errorf(\"old_string and new_string are identical; no change would be made\")\n\t}\n\tn := strings.Count(content, oldString)\n\tif n == 0 {\n\t\treturn \"\", 0, fmt.Errorf(\"old_string was not found in the file. Copy the exact text (including whitespace) from the file\")\n\t}\n\tif n > 1 && !replaceAll {\n\t\treturn \"\", 0, fmt.Errorf(\n\t\t\t\"old_string matched %d times. Include more surrounding context so it is unique, or set replace_all=true\",\n\t\t\tn,\n\t\t)\n\t}\n\tif replaceAll {\n\t\treturn strings.ReplaceAll(content, oldString, newString), n, nil\n\t}\n\treturn strings.Replace(content, oldString, newString, 1), 1, nil","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/sandbox_edit.go#L260-L296","documentation":"applySandboxEdit precondition guard: old_string is empty, so there is no text to locate and replace; the edit helper refuses to run because an empty search string would match everywhere and corrupt the file.","triggerScenarios":"Thrown at internal/agent/tools/sandbox_edit.go:278 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Copy the exact target text (including whitespace) into old_string","Validate old_string is non-empty before invoking the edit tool","For whole-content rewrites use a write tool instead of an edit"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}