earendil-works/pi · error

Could not edit file: . .

Error message

Could not edit file: ${path}. ${errorMessage}.

What it means

Umbrella error report at the end of the edit tool's execute: a lower-level operation on the file failed (existence check, read, write, or replacement matching) and the underlying errorMessage is appended with the file path. The cause is whichever filesystem/matching failure preceded it.

Solutions

  1. Read the appended errorMessage to identify the real cause (file missing, oldText not found, permissions)
  2. Verify the file exists and oldText matches the file exactly
  3. Fix the underlying issue and rerun the edit
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at packages/coding-agent/src/core/tools/edit.ts:354 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/6ea74ea7fcc66cf4. Report an issue: GitHub.

Appendix: source

Thrown at packages/coding-agent/src/core/tools/edit.ts:354

			return withFileMutationQueue(absolutePath, async () => {
				// Do not reject from an abort event listener here: that would release the
				// mutation queue while an in-flight filesystem operation may still finish.
				// Checking signal.aborted after each await observes the same aborts while
				// keeping the queue locked until the current operation has settled.
				const throwIfAborted = (): void => {
					if (signal?.aborted) throw new Error("Operation aborted");
				};

				throwIfAborted();

				// Check if file exists.
				try {
					await ops.access(absolutePath);
				} catch (error: unknown) {
					throwIfAborted();
					const errorMessage =
						error instanceof Error && "code" in error ? `Error code: ${error.code}` : String(error);
					throw new Error(`Could not edit file: ${path}. ${errorMessage}.`);
				}
				throwIfAborted();

				// Read the file.
				const buffer = await ops.readFile(absolutePath);
				const rawContent = buffer.toString("utf-8");
				throwIfAborted();

				// Strip BOM before matching. The model will not include an invisible BOM in oldText.
				const { bom, text: content } = splitBom(rawContent);
				const originalEnding = detectLineEnding(content);
				const normalizedContent = normalizeToLF(content);
				const { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);
				throwIfAborted();

				const finalContent = bom + restoreLineEndings(newContent, originalEnding);
				await ops.writeFile(absolutePath, finalContent);
				throwIfAborted();

View on GitHub (pinned to 4af9d21d3b)