can1357/oh-my-pi · error

Local file not found: ${url.href}

Error message

Local file not found: ${url.href}

What it means

After computing the target path and verifying containment, resolveLocalTarget calls fs.realpath on the target. When it fails with ENOENT the handler throws this friendly 'file not found' error carrying the original URL href, distinguishing a missing file from other fs failures.

Source

Thrown at packages/coding-agent/src/internal-urls/local-protocol.ts:379

	if (targetPath === resolvedRoot) {
		return { kind: "listing", root: resolvedRoot };
	}

	const parentDir = path.dirname(targetPath);
	try {
		const realParent = await fs.realpath(parentDir);
		ensureWithinRoot(realParent, resolvedRoot);
	} catch (error) {
		if (!isEnoent(error)) throw error;
	}

	let realTargetPath: string;
	try {
		realTargetPath = await fs.realpath(targetPath);
	} catch (error) {
		if (isEnoent(error)) {
			throw new Error(`Local file not found: ${url.href}`);
		}
		throw error;
	}

	ensureWithinRoot(realTargetPath, resolvedRoot);

	const stat = await fs.stat(realTargetPath);
	if (stat.isDirectory()) {
		return { kind: "directory", path: realTargetPath };
	}
	if (!stat.isFile()) {
		throw new Error(`local:// URL must resolve to a file or directory: ${url.href}`);
	}
	return { kind: "file", path: realTargetPath, size: stat.size };
}

/**
 * Resolve a local:// URL to a regular on-disk file, applying the same

View on GitHub (pinned to 9690622007)

Solutions

  1. Run a resolve of local:// (the root listing) to see which files actually exist.
  2. Write the file first via the write tool with path local://<name>, then read it.
  3. Fix typos / case in the URL path; remember local:// is scoped to the current session's local root, not the repo.
Defensive patterns

Strategy: try-catch

Validate before calling

const listing = await handler.resolve(parseInternalUrl('local://'), ctx); // read listing content to confirm the file name exists

Try / catch

try { resource = await handler.resolve(url, ctx); } catch (e) { if (String(e.message).startsWith('Local file not found')) { /* write the file first or correct the path */ } else throw e; }

Prevention

When it happens

Trigger: Reading local://notes.md when no notes.md was ever written under the session local root; a typo in the URL path; referencing a file from an earlier session whose local root was different; case-mismatched names on case-sensitive filesystems.

Common situations: Agents referencing local:// artifacts before writing them; sessions where copyLocalArtifacts did not run across a handoff so prior artifacts are absent; users assuming local:// spans the whole filesystem rather than the session root.

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/709e4c7496a95b0b. Report an issue: GitHub.