Files
openclaw/packages/normalization-core/src/promise-like.ts
T
Peter Steinberger 1220a7609a refactor: consolidate promise-like guards (#121861)
* feat(normalization-core): add promise-like guard

* refactor: consolidate promise-like guards

* fix(normalization-core): keep isPromiseLike non-throwing on hostile then getters

ClawSweeper finding on #121861: the diagnostics-path local guard caught throwing
then getters; the canonical guard must classify, never throw.

* test(normalization-core): annotate intentional hostile-thenable fixture
2026-08-10 22:50:48 -07:00

14 lines
522 B
TypeScript

/** Canonical thenable guard; use instead of local isPromiseLike copies. */
export function isPromiseLike<T = unknown>(value: unknown): value is PromiseLike<T> {
if (value === null || (typeof value !== "object" && typeof value !== "function")) {
return false;
}
// A hostile/exotic object can throw from its `then` getter; a guard must
// classify, never throw (diagnostics streams rely on this).
try {
return typeof (value as { then?: unknown }).then === "function";
} catch {
return false;
}
}