{"record":{"id":"19cd1827e9f89abe","repo":"microsoft/vscode","slug":"invalidpatchtext","errorCode":"invalidPatchText","errorMessage":"Invalid patch text","messagePattern":"Invalid patch text","errorType":"exception","errorClass":"InvalidPatchFormatError","httpStatus":null,"severity":"error","filePath":"extensions/copilot/src/extension/tools/node/applyPatch/parser.ts","lineNumber":778,"sourceCode":"\tif (index < lines.length && lines[index] === END_OF_FILE_PREFIX) {\n\t\tindex += 1;\n\t\treturn { nextChunkContext: old, chunks, endPatchIndex: index, eof: true, fuzzMerges: fuzzMergeNo };\n\t}\n\n\treturn { nextChunkContext: old, chunks, endPatchIndex: index, eof: false, fuzzMerges: fuzzMergeNo };\n}\n\n// -----------------------------------------------------------------------------\n// High‑level helpers\n// -----------------------------------------------------------------------------\n\nexport function text_to_patch(\n\ttext: string,\n\torig: Record<string, AbstractDocumentWithLanguageId | TextDocument>,\n): [Patch, number] {\n\tconst lines = text.trim().split('\\n');\n\tif (lines.length < 2) {\n\t\tthrow new InvalidPatchFormatError('Invalid patch text', 'invalidPatchText');\n\t}\n\tconst patchPrefix = PATCH_PREFIX.trim();\n\tif (!(lines[0] ?? '').startsWith(patchPrefix)) {\n\t\tthrow new InvalidPatchFormatError(`Invalid patch text. Patch must start with ${patchPrefix}.`, 'invalidPatchTextPrefix');\n\t}\n\tconst patchSuffix = PATCH_SUFFIX.trim();\n\tif (lines[lines.length - 1] !== patchSuffix) {\n\t\tlines.push(patchSuffix);\n\t}\n\tconst parser = new Parser(orig, lines);\n\tparser.index = 1;\n\tparser.parse();\n\treturn [parser.patch, parser.fuzz];\n}\n\nexport function identify_files_affected(text: string): Array<string> {\n\tconst lines = text.trim().split('\\n');\n\tconst result = new Set<string>();","sourceCodeStart":760,"sourceCodeEnd":796,"githubUrl":"https://github.com/microsoft/vscode/blob/a94b963a32aa9749d69504576791fa29700ae46d/extensions/copilot/src/extension/tools/node/applyPatch/parser.ts#L760-L796","documentation":"Error \"Invalid patch text\" thrown in microsoft/vscode.","triggerScenarios":"Thrown at extensions/copilot/src/extension/tools/node/applyPatch/parser.ts:778 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"a94b963a32aa9749d69504576791fa29700ae46d","analyzedAt":"2026-08-12T01:08:56.794Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}