can1357/oh-my-pi · error

Share upload to ${base} failed: ${err instanceof Error ? err

Error message

Share upload to ${base} failed: ${err instanceof Error ? err.message : String(err)}

What it means

uploadToServer POSTs the sealed session blob to the share server as application/octet-stream. If the fetch itself throws — DNS failure, connection refused, TLS error, network timeout, request aborted — the raw low-level error is wrapped in this error naming the server base URL, so the caller gets one clear message instead of a bare TypeError.

Source

Thrown at packages/coding-agent/src/export/share.ts:675

	return {
		url: `${base}/${id}#${keyText}`,
		method: "server",
		truncated: forServer.truncated,
		sealedBytes: forServer.sealed.byteLength,
	};
}

/** POST the sealed blob to the share server; returns the assigned id. */
async function uploadToServer(sealed: Uint8Array, base: string): Promise<string> {
	let res: Response;
	try {
		res = await fetch(base, {
			method: "POST",
			headers: { "Content-Type": "application/octet-stream" },
			body: sealed,
		});
	} catch (err) {
		throw new Error(`Share upload to ${base} failed: ${err instanceof Error ? err.message : String(err)}`);
	}
	if (!res.ok) {
		const detail = (await res.text().catch(() => "")).trim().slice(0, 200);
		throw new Error(`Share upload to ${base} failed: HTTP ${res.status}${detail ? ` (${detail})` : ""}`);
	}
	const body = (await res.json().catch(() => null)) as { id?: unknown } | null;
	const id = body && typeof body.id === "string" ? body.id : "";
	if (!/^[A-Za-z0-9_-]{10,64}$/.test(id)) {
		throw new Error(`Share upload to ${base} failed: server returned no usable id`);
	}
	return id;
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Check network connectivity and that the share server host resolves and is reachable (curl -v POST to the base URL).
  2. Verify the configured share server URL (env/config) — fix typos, protocol (https vs http), and trailing path.
  3. Retry after transient failures; if a proxy/firewall is in the path, allowlist the share host.
  4. If self-hosting, confirm the share server process is running and its port is exposed.
  5. If the underlying err.message says 'fetch failed', inspect cause (e.g. ENOTFOUND, ECONNREFUSED) to pinpoint DNS vs connection issues.

Example fix

// before
const url = await share.forServerUrl('https://share.internal.example/share'); // ECONNREFUSED
// after
// fix config / verify reachability first:
const base = process.env.OMP_SHARE_URL ?? 'https://share.oh-my-pi.dev';
const url = await share.forServerUrl(base);
Defensive patterns

Strategy: retry

Validate before calling

// Cheap reachability probe before upload
const base = normalizeShareServerUrl(serverUrl);
const probe = await fetch(base, { method: 'HEAD' }).catch(() => null);
if (!probe) throw new Error(`Share server ${base} unreachable`);

Try / catch

try {
  const id = await uploadToServer(base, sealed);
} catch (err) {
  if (err instanceof Error && err.message.startsWith('Share upload to')) {
    // inspect err.message for the low-level cause; retry with backoff or fall back to gist
  } else throw err;
}

Prevention

When it happens

Trigger: Calling share.forServer/uploadToServer when the share server base URL is unreachable: wrong hostname, server down, offline, blocked by proxy/firewall, or a malformed URL that fetch rejects before a response is received.

Common situations: No internet/VPN connection; self-hosted share server configured with a typo'd or stale URL (SHARE_SERVER env/config); corporate proxy blocking the POST; server temporarily down for maintenance; IPv6/DNS misconfiguration.

Related errors


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