Improve wait(...) input validation error message

This commit is contained in:
Konstantin Wohlwend 2024-10-18 11:57:33 -07:00
parent 787d6ecce4
commit 48a5b07a31

View File

@ -110,10 +110,10 @@ export function ignoreUnhandledRejection<T extends Promise<any>>(promise: T): T
export async function wait(ms: number) {
if (!Number.isFinite(ms) || ms < 0) {
throw new StackAssertionError("wait() requires a non-negative integer number of milliseconds to wait.");
throw new StackAssertionError(`wait() requires a non-negative integer number of milliseconds to wait. (found: ${ms}ms)`);
}
if (ms >= 2**31) {
throw new StackAssertionError("The maximum timeout for wait() is 2147483647ms (2**31 - 1).");
throw new StackAssertionError("The maximum timeout for wait() is 2147483647ms (2**31 - 1). (found: ${ms}ms)");
}
return await new Promise<void>(resolve => setTimeout(resolve, ms));
}