can1357/oh-my-pi · error · Error

${context} omitted ${field}

Error message

${context} omitted ${field}

What it means

requiredStringField extracts a required string field from an already-validated JSON object and throws `${context} omitted ${field}` when the field is missing, not a string, or an empty string. It is used for B2 fields like accountId, authorizationToken, apiUrl, bucketId, and bucketType, so an incomplete API response surfaces with a message naming the exact stage and field.

Source

Thrown at packages/coding-agent/src/blob-broker/uploaders-object-storage.ts:438

			const publicUrl = publicBaseUrl ? publicObjectUrl(publicBaseUrl, key) : url.toString();
			return publication(destination, uploadRequest, publicUrl, {
				remoteId: key,
				delete: { method: "DELETE", url: url.toString(), headers: deleteHeaders },
			});
		},
	};
}

function asRecord(value: unknown, context: string): Record<string, unknown> {
	if (typeof value !== "object" || value === null || Array.isArray(value)) {
		throw new Error(`${context} returned an invalid JSON object`);
	}
	return value as Record<string, unknown>;
}

function requiredStringField(value: unknown, field: string, context: string): string {
	const result = asRecord(value, context)[field];
	if (typeof result !== "string" || result.length === 0) throw new Error(`${context} omitted ${field}`);
	return result;
}

function optionalStringField(value: unknown, field: string): string | undefined {
	if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined;
	const result = (value as Record<string, unknown>)[field];
	return typeof result === "string" ? result : undefined;
}

async function sha1Hex(bytes: Uint8Array): Promise<string> {
	const digest = new Uint8Array(await crypto.subtle.digest("SHA-1", strictBytes(bytes)));
	let result = "";
	for (const byte of digest) result += byte.toString(16).padStart(2, "0");
	return result;
}

async function b2Json(
	config: DestinationRuntimeConfig,

View on GitHub (pinned to 9690622007)

Solutions

  1. Log the full JSON body from the failing stage (`context` tells you which) and inspect which field is absent.
  2. Re-run b2_authorize_account manually (curl) to confirm the API returns the expected fields for your account/key.
  3. Verify the application key has permissions for the operation; restricted keys can yield reduced responses.
  4. Check for a B2 API version mismatch and pin/update the /b2api/v2/ calls accordingly.

Example fix

// before
// assuming authorization always has apiUrl
const bucketUrl = authorization.apiUrl + "/file/" + bucketName;
// after
const apiUrl = requiredStringField(authorization, "apiUrl", "Backblaze B2 authorization"); // throws with a clear message if absent
const bucketUrl = apiUrl + "/file/" + bucketName;
Defensive patterns

Strategy: validation

Validate before calling

function assertFields(obj: Record<string, unknown>, fields: string[], context: string): void {
  for (const f of fields) {
    const v = obj[f];
    if (typeof v !== "string" || v.length === 0) throw new Error(`${context} omitted ${f}`);
  }
}
// assertFields(authJson, ["accountId", "authorizationToken", "apiUrl"], "B2 authorization");

Type guard

function hasStringField(v: unknown, field: string): v is Record<string, string> {
  return typeof v === "object" && v !== null && typeof (v as Record<string, unknown>)[field] === "string"
    && ((v as Record<string, unknown>)[field] as string).length > 0;
}

Try / catch

try {
  const target = await b2UploadTarget(config, authorization, bucketId);
} catch (err) {
  if (err instanceof Error && / omitted \w+$/.test(err.message)) {
    logger.error("B2 response missing field; re-authorize and check key capabilities", { err });
  } else throw err;
}

Prevention

When it happens

Trigger: A B2 API response object (authorization, bucket record, upload target) lacks a required field or contains it as null/empty — e.g. b2_authorize_account returning partial JSON, or a bucket record missing bucketId/bucketType because the API version changed.

Common situations: B2 account restricted so authorization omits allowed-capability fields; API response schema drift after a B2 API update; intermittent truncated response parsed as valid JSON with absent fields; wrong endpoint returning a minimal error object with 200 status.

Related errors


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