JuliusBrussee/caveman · error
recordOutcome: no global fetch; pass client.fetch
Error message
recordOutcome: no global fetch; pass client.fetch
What it means
Environment guard in recordOutcome's globalFetch helper: neither a custom fetch was supplied via client.fetch nor a global fetch (globalThis.fetch) exists, so the HTTP call to the control API cannot be made at all.
Solutions
- Pass a fetch implementation in the client options: recordOutcome(..., { fetch: myFetch })
- Run on Node 18+ or a runtime where globalThis.fetch is defined
- Polyfill globalThis.fetch (e.g. undici or node-fetch) before calling recordOutcome
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at packages/mastra/src/index.ts:723 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18).
Data as JSON: /api/errors/83f3243bc4e73575.
Report an issue: GitHub.
Appendix: source
Thrown at packages/mastra/src/index.ts:723
);
const text = await response.text();
const ok = response.ok ?? (response.status >= 200 && response.status < 300);
if (!ok) throw new CavemanOutcomeError(response.status, text);
let parsed: { data?: unknown; created?: unknown };
try {
parsed = JSON.parse(text) as { data?: unknown; created?: unknown };
} catch {
throw new CavemanOutcomeError(response.status, text);
}
return { status: response.status, created: parsed.created === true, record: parsed.data ?? null };
}
function globalFetch(url: string, init: RequestInitLike): Promise<ResponseLike> {
const fetchImpl = (globalThis as { fetch?: (u: string, i: unknown) => Promise<ResponseLike> }).fetch;
if (typeof fetchImpl !== "function") {
throw new Error("recordOutcome: no global fetch; pass client.fetch");
}
return fetchImpl(url, init);
}
/**
* JSON with object keys sorted at every level. Throws on anything that is not a
* plain object, array, string, finite number, boolean, or null — a Date, a Map,
* or a class instance would serialize into something the caller did not mean,
* and the record's digest is its identity.
*/
export function stableStringify(value: unknown, path = "value"): string {
if (value === null) return "null";
switch (typeof value) {
case "string":
return JSON.stringify(value);
case "boolean":
return value ? "true" : "false";
case "number":View on GitHub (pinned to 766dce6b13)