can1357/oh-my-pi · error

Host URI read failed for ${url.href}

Error message

Host URI read failed for ${url.href}

What it means

requestRead dispatches a read to the scheme's registered handler via RPC and, if the handler replies with isError or returns neither error nor content, throws 'Host URI read failed for <url>'. The remote read result was an error (or empty), so no resource can be returned.

Source

Thrown at packages/coding-agent/src/modes/rpc/host-uris.ts:157

		if (!pending) return false;
		this.#pending.delete(frame.id);
		pending.resolve(frame);
		return true;
	}

	rejectAllPending(message: string): void {
		const error = new Error(message);
		const pending = Array.from(this.#pending.values());
		this.#pending.clear();
		for (const entry of pending) {
			entry.reject(error);
		}
	}

	async requestRead(scheme: string, url: InternalUrl, context?: ResolveContext): Promise<InternalResource> {
		const result = await this.#dispatch("read", url.href, undefined, context?.signal);
		if (result.isError) {
			throw new Error(result.error || result.content || `Host URI read failed for ${url.href}`);
		}
		const content = result.content ?? "";
		const contentType = result.contentType ?? "text/plain";
		const definition = this.#definitions.get(scheme);
		return {
			url: url.href,
			content,
			contentType,
			size: Buffer.byteLength(content, "utf-8"),
			notes: result.notes && result.notes.length > 0 ? [...result.notes] : undefined,
			immutable: result.immutable ?? definition?.immutable === true,
		};
	}

	async requestWrite(_scheme: string, url: InternalUrl, content: string, context?: WriteContext): Promise<void> {
		const result = await this.#dispatch("write", url.href, content, context?.signal);
		if (result.isError) {
			throw new Error(result.error || result.content || `Host URI write failed for ${url.href}`);

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the underlying handler error — the thrown message uses result.error || result.content, so capture it (catch and inspect message/cause) for the real cause
  2. Verify the URL target exists and the host process can access it (permissions, path validity)
  3. Check that the scheme handler is correctly registered and functioning on the host side (setSchemes/dispatch wiring)
  4. Retry if the failure was transient (network/remote service); otherwise surface the handler error to the user

Example fix

// before
const resource = await hostUris.requestRead(scheme, url);
// after
let resource;
try {
  resource = await hostUris.requestRead(scheme, url);
} catch (e) {
  logger.warn("Host URI read failed", { url: url.href, error: String(e) });
  resource = fallbackResource; // or re-throw after logging
}
Defensive patterns

Strategy: try-catch

Validate before calling

const def = hostUris.getScheme?.(scheme); // ensure a handler is registered
if (!def) throw new Error(`No handler registered for scheme: ${scheme}`);
await assertUrlReachable(url.href); // app-specific preflight, if available

Try / catch

try {
  const resource = await hostUris.requestRead(scheme, url, ctx);
} catch (err) {
  if (err.message.startsWith("Host URI read failed")) {
    // message body carries the handler's error/content — surface it
    ui.showError(`Could not read ${url.href}: ${err.message}`);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling requestRead(scheme, url) where the dispatched handler responds with result.isError === true (result.error/content used as the message), or returns an empty result with no error text or content for the given URL.

Common situations: The host-side handler for the scheme cannot read the target (missing file, permission denied, remote service down); the handler crashed and returned an empty/undefined result; the URL points to a resource that no longer exists.

Related errors


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