can1357/oh-my-pi · error · ToolError

data is required for write_memory

Error message

data is required for write_memory

What it means

For action="write_memory", params.data carries the bytes to write (after the required memory_reference). When data is absent or empty the tool throws this ToolError before any adapter interaction. Writing zero bytes is not a meaningful DAP writeMemory call, so the tool treats it as a caller mistake.

Source

Thrown at packages/coding-agent/src/tools/debug.ts:1043

					params.memory_reference,
					params.count,
					params.offset,
					combinedSignal,
					timeoutSec * 1000,
				);
				details.snapshot = response.snapshot;
				details.memoryAddress = response.address;
				details.memoryData = response.data;
				details.unreadableBytes = response.unreadableBytes;
				return result.text(formatMemoryRead(response.address, response.data, response.unreadableBytes)).done();
			}
			case "write_memory": {
				requireCapability("supportsWriteMemoryRequest", "memory writes");
				if (!params.memory_reference) {
					throw new ToolError("memory_reference is required for write_memory");
				}
				if (!params.data) {
					throw new ToolError("data is required for write_memory");
				}
				const response = await dapSessionManager.writeMemory(
					params.memory_reference,
					params.data,
					params.offset,
					params.allow_partial,
					combinedSignal,
					timeoutSec * 1000,
				);
				details.snapshot = response.snapshot;
				details.bytesWritten = response.bytesWritten;
				return result
					.text(
						[
							"Memory write completed.",
							...(response.bytesWritten !== undefined ? [`Bytes written: ${response.bytesWritten}`] : []),
							...(response.offset !== undefined ? [`Offset: ${response.offset}`] : []),
						].join("\n"),

View on GitHub (pinned to 9690622007)

Solutions

  1. Pass the payload as a non-empty data string (hex-encoded bytes, matching the tool's expected format).
  2. Validate the payload is non-empty before invoking the tool.
  3. Use the correct key: data, not value/bytes/content.
  4. To probe writability, use a real 1–2 byte write or rely on read_memory's unreadableBytes instead of an empty write.

Example fix

// before
await debugTool.run({ action: "write_memory", memory_reference: ref, data: "" });
// after
await debugTool.run({ action: "write_memory", memory_reference: ref, data: "9090", allow_partial: false });
Defensive patterns

Strategy: validation

Validate before calling

if (typeof data !== "string" || data.length === 0) throw new Error("write_memory requires a non-empty hex data payload");
if (!/^[0-9a-fA-F]+$/.test(data)) throw new Error("data must be a hex string");

Type guard

function hasPayload(p: { data?: string }): p is { data: string } {
  return typeof p.data === "string" && p.data.length > 0;
}

Try / catch

try {
  await debugTool.run({ action: "write_memory", memory_reference: ref, data: hex, allow_partial: false });
} catch (err) {
  if (err instanceof ToolError && err.message.includes("data is required")) {
    // inspect the payload encoding step; fix and re-issue the write
  } else throw err;
}

Prevention

When it happens

Trigger: Calling write_memory with a valid memory_reference but params.data undefined, null, or an empty string — e.g. the payload variable was never populated or the hex string was trimmed to empty.

Common situations: Generated tool calls with the payload under a different key (value, bytes, content); pipelines where an earlier encoding step produced an empty string and the empty check was skipped upstream; accidental no-op writes intended to "probe" writability.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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