can1357/oh-my-pi · error · Error

owncloud share response did not include OCS metadata and dat

Error message

owncloud share response did not include OCS metadata and data

What it means

This error is thrown by the ownCloudShare response validator when the ownCloud/Nextcloud OCS API response JSON contains an 'ocs' envelope, but that envelope lacks either the 'meta' or 'data' object. The library expects the standard OCS response shape { ocs: { meta: {...}, data: {...} } } when parsing a share-creation reply; anything else is treated as a malformed or unexpected response rather than a valid share.

Source

Thrown at packages/coding-agent/src/blob-broker/uploaders-self-hosted.ts:55

	id: string;
	name?: string;
}

function nonEmptyString(value: unknown): string | undefined {
	return typeof value === "string" && value.length > 0 ? value : undefined;
}

function identifier(value: unknown): string | undefined {
	return typeof value === "string" || typeof value === "number" ? String(value) : undefined;
}

function ownCloudShare(value: unknown): OwnCloudShare {
	if (typeof value !== "object" || value === null || !("ocs" in value)) {
		throw new Error("owncloud share response did not include an OCS envelope");
	}
	const ocs = value.ocs;
	if (typeof ocs !== "object" || ocs === null || !("meta" in ocs) || !("data" in ocs)) {
		throw new Error("owncloud share response did not include OCS metadata and data");
	}
	const meta = ocs.meta;
	const data = ocs.data;
	if (typeof meta !== "object" || meta === null || !("statuscode" in meta)) {
		throw new Error("owncloud share response did not include an OCS status");
	}
	if (typeof data !== "object" || data === null || !("url" in data)) {
		throw new Error("owncloud share response did not include a URL");
	}
	const url = nonEmptyString(data.url);
	if (!url) throw new Error("owncloud share response did not include a URL");
	const id = "id" in data ? identifier(data.id) : undefined;
	return { statusCode: meta.statuscode, url, ...(id ? { id } : {}) };
}

function plikUpload(value: unknown): PlikUpload {
	if (typeof value !== "object" || value === null || !("id" in value) || !("uploadToken" in value)) {
		throw new Error("plik upload metadata did not include an id and upload token");

View on GitHub (pinned to 9690622007)

Solutions

  1. Verify the destination's apiUrl points at the correct OCS endpoint (e.g. https://host/ocs/v1.php or /ocs/v2.php apps path) and the server actually responds with OCS JSON
  2. Check for reverse proxies / SSO redirects rewriting the response; test the share endpoint directly with curl using the same credentials
  3. Confirm server and client OCS API versions match (Nextcloud 'Accept: application/json' vs XML) and upgrade/downgrade accordingly
  4. Log the raw response body at the failure point to see what the server actually returned

Example fix

// before: response body is a proxy JSON page like {"error":"auth required"}
url = "https://mycloud.example.com/remote.php/webdav" // wrong endpoint
// after: use the OCS share endpoint expected by the uploader
url = "https://mycloud.example.com/ocs/v1.php/apps/files_sharing/api/v1/shares"
Defensive patterns

Strategy: type-guard

Validate before calling

function looksLikeOcsResponse(value: unknown): boolean {
  return (
    typeof value === "object" && value !== null && "ocs" in value &&
    typeof (value as any).ocs === "object" && (value as any).ocs !== null &&
    "meta" in (value as any).ocs && "data" in (value as any).ocs
  );
}

Type guard

function isOcsEnvelope(value: unknown): value is { ocs: { meta: object; data: object } } {
  if (typeof value !== "object" || value === null || !("ocs" in value)) return false;
  const ocs = (value as { ocs?: unknown }).ocs;
  return typeof ocs === "object" && ocs !== null && "meta" in ocs && "data" in ocs;
}

Try / catch

try {
  const share = await uploader.share();
} catch (err) {
  if ((err as Error).message.includes("OCS envelope")) {
    logger.error("ownCloud endpoint did not return OCS JSON — check apiUrl and proxies", { err });
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling the ownCloud/Nextcloud share uploader (createOwnCloudUploader -> share -> ownCloudShare) against a server whose HTTP 2xx body is not a well-formed OCS envelope — e.g. the response parsed as JSON but 'ocs' contains only partial fields, or a proxy/gateway returned a JSON body without 'meta'/'data'.

Common situations: Pointing the destination at a Nextcloud instance with OCS API version mismatch (e.g. old v1 vs v2 metadata paths), a reverse proxy or CDN intercepting the request and returning its own JSON error page with 200, or an HTML/XML login redirect being coerced through a different parser path.

Related errors


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