can1357/oh-my-pi · warning · Error

(augmented with "\nCurrent file content near the closest…

Error message

${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)

What it means

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.

Solutions

  1. Read the appended preview and adjust PATTERN to exactly match the current file text shown.
  2. Use the atomicity notice as reassurance: retry freely; a failed multi-operation application changes nothing.
  3. If the message already includes a copy-ready payload or interpretation, fix that payload directly instead of re-deriving it.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  applySloppyEdit(payload);
} catch (err) {
  if (err instanceof Error && err.message.includes("Current file content near the closest match")) {
    const preview = err.message.split("no re-read needed):\n")[1]?.split("\n")[0];
    // file is unchanged (atomic); re-author payload using the preview
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/68a9bfd8ff45e06e. Report an issue: GitHub.

Appendix: source

Thrown at packages/coding-agent/src/edit/sloppy.ts:3875

}

function apply(content: string, input: string, context: SloppyApplyContext): string {
	try {
		return applyOperations(content, input, context);
	} catch (error) {
		if (!(error instanceof Error)) throw error;
		let message = error.message;
		if (
			!message.includes("Current file content near the closest match (no re-read needed):") &&
			!/\bNear line \d+:/u.test(message) &&
			!message.includes("Copy-ready corrected operation:") &&
			!message.includes("Copy-ready corrected payload:") &&
			!message.includes("Copy-ready per-selection interpretation:")
		) {
			message += `\nCurrent file content near the closest match (no re-read needed):\n${numberedPreview(content, 0)}`;
		}
		if (!message.includes(ATOMICITY_NOTICE)) message += `\n${ATOMICITY_NOTICE}`;
		throw new Error(message);
	}
}

/** The official sloppy implementation; docs re-skinned to the active marker alphabet. */
export const sloppyVariant: SloppyVariant = { id: "sloppy", description, apply };

/** Lark grammar for constrained decoding, in the active marker alphabet. */
export const sloppyGrammar: string = sloppyGrammarSource;

export interface ExecuteSloppyOptions {
	session: ToolSession;
	/** Payload sections with display paths already workspace-resolved. */
	sections: SloppySection[];
	signal?: AbortSignal;
	batchRequest?: LspBatchRequest;
	writethrough: WritethroughCallback;
	beginDeferredDiagnosticsForPath: (path: string) => WritethroughDeferredHandle;
	/** Observes a committed content transition before result snapshots are pruned. */

View on GitHub (pinned to 9690622007)