mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-24 19:35:28 -06:00
1220a7609a
* 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
14 lines
522 B
TypeScript
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;
|
|
}
|
|
}
|