{"record":{"id":"68a9bfd8ff45e06e","repo":"can1357/oh-my-pi","slug":"error-message-augmented-with-ncurrent-file-c","errorCode":null,"errorMessage":"${error.message} (augmented with \"\\nCurrent file content near the closest match (no re-read needed):\\n${numberedPreview(content, 0)}\" when lacking grounding, plus the atomicity notice)","messagePattern":"(.+?) \\(augmented with \"\\\\nCurrent file content near the closest match \\(no re-read needed\\):\\\\n(.+?)\" when lacking grounding, plus the atomicity notice\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/coding-agent/src/edit/sloppy.ts","lineNumber":3875,"sourceCode":"}\n\nfunction apply(content: string, input: string, context: SloppyApplyContext): string {\n\ttry {\n\t\treturn applyOperations(content, input, context);\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\tlet message = error.message;\n\t\tif (\n\t\t\t!message.includes(\"Current file content near the closest match (no re-read needed):\") &&\n\t\t\t!/\\bNear line \\d+:/u.test(message) &&\n\t\t\t!message.includes(\"Copy-ready corrected operation:\") &&\n\t\t\t!message.includes(\"Copy-ready corrected payload:\") &&\n\t\t\t!message.includes(\"Copy-ready per-selection interpretation:\")\n\t\t) {\n\t\t\tmessage += `\\nCurrent file content near the closest match (no re-read needed):\\n${numberedPreview(content, 0)}`;\n\t\t}\n\t\tif (!message.includes(ATOMICITY_NOTICE)) message += `\\n${ATOMICITY_NOTICE}`;\n\t\tthrow new Error(message);\n\t}\n}\n\n/** The official sloppy implementation; docs re-skinned to the active marker alphabet. */\nexport const sloppyVariant: SloppyVariant = { id: \"sloppy\", description, apply };\n\n/** Lark grammar for constrained decoding, in the active marker alphabet. */\nexport const sloppyGrammar: string = sloppyGrammarSource;\n\nexport interface ExecuteSloppyOptions {\n\tsession: ToolSession;\n\t/** Payload sections with display paths already workspace-resolved. */\n\tsections: SloppySection[];\n\tsignal?: AbortSignal;\n\tbatchRequest?: LspBatchRequest;\n\twritethrough: WritethroughCallback;\n\tbeginDeferredDiagnosticsForPath: (path: string) => WritethroughDeferredHandle;\n\t/** Observes a committed content transition before result snapshots are pruned. */","sourceCodeStart":3857,"sourceCodeEnd":3893,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/edit/sloppy.ts#L3857-L3893","documentation":"The top-level catch in applySloppyEdit augments any error message with grounding and atomicity context before re-throwing. If the message does not already contain a copy-ready section or the closest-match preview, a numbered preview of the file content (from offset 0) is appended so the author can see the current text without re-reading; the ATOMICITY_NOTICE is appended if absent, stating that failed applications leave the file untouched.","triggerScenarios":"Any error thrown during application (no-match, ambiguity, overlap, parse) reaching the catch at sloppy.ts:3875 whose message lacks 'Current file content near the closest match' and the copy-ready markers; the augmented message is re-thrown.","commonSituations":"Model iterating on a failing edit payload and needing file context to fix it; callers logging this error and seeing the file preview plus atomicity guarantee; duplicate-augmentation avoided for already-grounded messages.","solutions":["Read the appended preview and adjust PATTERN to exactly match the current file text shown.","Use the atomicity notice as reassurance: retry freely; a failed multi-operation application changes nothing.","If the message already includes a copy-ready payload or interpretation, fix that payload directly instead of re-deriving it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  applySloppyEdit(payload);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Current file content near the closest match\")) {\n    const preview = err.message.split(\"no re-read needed):\\n\")[1]?.split(\"\\n\")[0];\n    // file is unchanged (atomic); re-author payload using the preview\n  } else throw err;\n}","preventionTips":["Treat failed applications as atomic: the file is untouched, so retry safely","Parse the appended numbered preview to re-anchor PATTERN to current file text","Match on the message substrings ('Copy-ready', 'Current file content') when programmatically handling sloppy errors, since augmentation is conditional"],"tags":["edit-dsl","error-augmentation","grounding"],"backgroundTag":"edit-apply-failure","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}