can1357/oh-my-pi · error

File not found: ${path}

Error message

File not found: ${path}

What it means

readEditFileText loads the text of a file (or its notebook virtual text) as the base for an edit operation. When the underlying read fails with ENOENT it rethrows a friendly 'File not found' error naming the display path, so callers get a clear message instead of a raw Bun filesystem error.

Source

Thrown at packages/coding-agent/src/edit/read-file.ts:16

/**
 * Shared file-read helper for edit-mode utilities.
 *
 * Reads a file via Bun and rethrows ENOENT as a user-facing "File not found"
 * error referencing the display path.
 */
import { isEnoent } from "@oh-my-pi/pi-utils";
import { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from "./notebook";

export async function readEditFileText(absolutePath: string, path: string): Promise<string> {
	try {
		if (isNotebookPath(absolutePath)) return await readEditableNotebookText(absolutePath, path);
		return await Bun.file(absolutePath).text();
	} catch (error) {
		if (isEnoent(error)) {
			throw new Error(`File not found: ${path}`);
		}
		throw error;
	}
}

export async function serializeEditFileText(absolutePath: string, path: string, content: string): Promise<string> {
	if (isNotebookPath(absolutePath)) return serializeEditedNotebookText(absolutePath, path, content);
	return content;
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Check the path exists (ls / stat) and correct any typo before editing
  2. Create the file first (use the create/write tool) if the intent was a new file
  3. Re-list the directory to confirm the current file name after refactors or renames
  4. If the path is relative, resolve it against the intended working directory

Example fix

// before
await readEditFileText(abs, 'src/old-name.ts')
// after
await readEditFileText(abs, 'src/new-name.ts') // after verifying via ls
Defensive patterns

Strategy: try-catch

Validate before calling

const file = Bun.file(absolutePath);
if (!(await file.exists())) throw new Error(`Refusing edit: ${path} does not exist`);

Try / catch

try {
  const text = await readEditFileText(abs, path);
  // edit...
} catch (err) {
  if (err instanceof Error && err.message.startsWith('File not found:')) {
    // recreate, correct path, or surface to user
  } else throw err;
}

Prevention

When it happens

Trigger: Calling any edit/read tool (read, rawContent, computeEditDiff, writeText, etc.) with a path that does not exist on disk — typically an edit against a file that was deleted, renamed, or never created, or a path with a typo/wrong working directory.

Common situations: Editing a file the agent believes exists but that was removed by a previous operation; typo in path; relative path resolved against the wrong root; race where another process deleted the file between listing and editing.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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