{"record":{"id":"d8c1a6db4df2a417","repo":"can1357/oh-my-pi","slug":"host-uri-write-failed-for-url-href","errorCode":null,"errorMessage":"Host URI write failed for ${url.href}","messagePattern":"Host URI write failed for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/modes/rpc/host-uris.ts","lineNumber":175,"sourceCode":"\t\t\tthrow new Error(result.error || result.content || `Host URI read failed for ${url.href}`);\n\t\t}\n\t\tconst content = result.content ?? \"\";\n\t\tconst contentType = result.contentType ?? \"text/plain\";\n\t\tconst definition = this.#definitions.get(scheme);\n\t\treturn {\n\t\t\turl: url.href,\n\t\t\tcontent,\n\t\t\tcontentType,\n\t\t\tsize: Buffer.byteLength(content, \"utf-8\"),\n\t\t\tnotes: result.notes && result.notes.length > 0 ? [...result.notes] : undefined,\n\t\t\timmutable: result.immutable ?? definition?.immutable === true,\n\t\t};\n\t}\n\n\tasync requestWrite(_scheme: string, url: InternalUrl, content: string, context?: WriteContext): Promise<void> {\n\t\tconst result = await this.#dispatch(\"write\", url.href, content, context?.signal);\n\t\tif (result.isError) {\n\t\t\tthrow new Error(result.error || result.content || `Host URI write failed for ${url.href}`);\n\t\t}\n\t}\n\n\t#dispatch(\n\t\toperation: \"read\" | \"write\",\n\t\turl: string,\n\t\tcontent: string | undefined,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<RpcHostUriResult> {\n\t\tif (signal?.aborted) {\n\t\t\treturn Promise.reject(new Error(`Host URI ${operation} for ${url} was aborted`));\n\t\t}\n\n\t\tconst id = Snowflake.next() as string;\n\t\tconst { promise, resolve, reject } = Promise.withResolvers<RpcHostUriResult>();\n\t\tlet settled = false;\n\n\t\tconst cleanup = () => {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/modes/rpc/host-uris.ts#L157-L193","documentation":"Thrown by RpcHostConnection.requestWrite (packages/coding-agent/src/modes/rpc/host-uris.ts:175) when the host-side 'write' dispatch for a host URI returns an error result. The thrown message is the host's own error text if present, otherwise this generic fallback naming the URI. It signals the child/host refused or failed a host-mediated resource write.","triggerScenarios":"Calling requestWrite where this.#dispatch(\"write\", url.href, content, signal) resolves with isError=true — the host rejected the write (permission denied, read-only resource) or returned an empty/error payload (result.error and result.content both empty yields the generic message).","commonSituations":"An agent session writes a resource the host has not granted write access to; the host tool handler throws internally; the user denies a permission prompt; the write is aborted via the supplied AbortSignal and the host reports it as an error.","solutions":["Read the thrown message (or result.error) for the host's underlying reason and fix that condition (permissions, resource state).","Verify the scheme is registered as writable on the host before calling requestWrite.","Pass a fresh AbortSignal only if cancellation is intended; a pre-aborted signal yields an immediate error.","If the resource is read-only, use requestRead instead of requestWrite."],"exampleFix":"// before\nawait connection.requestWrite(\"file\", url, content, { signal: staleSignal });\n// after\nif (!staleSignal.aborted) {\n  await connection.requestWrite(\"file\", url, content);\n}","handlingStrategy":"try-catch","validationCode":"if (signal?.aborted) throw new Error(\"write aborted before dispatch\");\nif (typeof content !== \"string\") throw new Error(\"write content must be a string\");","typeGuard":"function isHostUrl(u: unknown): u is URL {\n  return u instanceof URL && u.protocol !== \"http:\" && u.protocol !== \"https:\";\n}","tryCatchPattern":"try {\n  await connection.requestWrite(scheme, url, content, { signal });\n} catch (err) {\n  logger.warn(\"host URI write failed\", { href: url.href, cause: String(err) });\n  // surface to user or fall back to read-only handling\n}","preventionTips":["Only write to schemes the host registered as writable.","Check AbortSignal state before dispatching.","Treat host tool errors as permission/state issues, not client bugs.","Inspect the host error text carried in the thrown message first."],"tags":["rpc","host-uri","write-failure","ipc"],"backgroundTag":"rpc-command-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}