earendil-works/pi · error · Error
Could not edit file: ${path}. Error code: ${error.code}.
Error message
Could not edit file: ${path}. Error code: ${error.code}. What it means
Error "Could not edit file: ${path}. Error code: ${error.code}." thrown in earendil-works/pi.
Source
Thrown at packages/agent/src/harness/tools/edit.ts:108
export function createEditTool<TContext extends ExecutionToolContext = ExecutionToolContext>(): AgentHarnessTool<
TContext,
typeof editSchema,
EditToolDetails | undefined
> {
return {
name: "edit",
label: "edit",
description:
"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",
parameters: editSchema,
prepareArguments: prepareEditArguments,
async execute(_toolCallId, input, signal, _onUpdate, { env }) {
const { path, edits } = validateEditInput(input);
const absolutePath = await resolveToolPath(env, path, signal);
return withFileMutationQueue(env, absolutePath, async () => {
if (signal?.aborted) throw new Error("Operation aborted");
const info = await env.fileInfo(absolutePath, signal);
if (!info.ok) throw editAccessError(path, info.error);
if (info.value.kind !== "file" && info.value.kind !== "symlink") {
throw new Error(`Could not edit file: ${path}. Path is not a file.`);
}
const readResult = await env.readTextFile(absolutePath, signal);
if (!readResult.ok) throw editAccessError(path, readResult.error);
if (signal?.aborted) throw new Error("Operation aborted");
const { bom, text: content } = stripBom(readResult.value);
const originalEnding = detectLineEnding(content);
const normalizedContent = normalizeToLF(content);
const { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);
if (signal?.aborted) throw new Error("Operation aborted");
const finalContent = bom + restoreLineEndings(newContent, originalEnding);
const writeResult = await env.writeFile(absolutePath, finalContent, signal);
if (!writeResult.ok) throw editAccessError(path, writeResult.error);
if (signal?.aborted) throw new Error("Operation aborted");View on GitHub (pinned to 4af9d21d3b)
Solutions
- The edit failed at the filesystem level; check the reported error code (permissions, missing path).
When it happens
Trigger: Thrown at packages/agent/src/harness/tools/edit.ts:108 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/bbb7092d1a154c00.
Report an issue: GitHub.