refactor(async): align the error messages to the style guide (#5758)

Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
Ian Bull 2024-08-22 02:02:58 -04:00 committed by GitHub
parent 46b3961833
commit 833a24f088
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 9 deletions

View File

@ -2,7 +2,8 @@
// This module is browser compatible. // This module is browser compatible.
/** Error message emitted from the thrown error while mapping. */ /** Error message emitted from the thrown error while mapping. */
const ERROR_WHILE_MAPPING_MESSAGE = "Threw while mapping."; const ERROR_WHILE_MAPPING_MESSAGE =
"Cannot complete the mapping as an error was thrown from an item";
/** /**
* pooledMap transforms values from an (async) iterable into another async * pooledMap transforms values from an (async) iterable into another async

View File

@ -38,7 +38,7 @@ Deno.test("pooledMap() handles errors", async () => {
} }
}, },
AggregateError, AggregateError,
"Threw while mapping.", "Cannot complete the mapping as an error was thrown from an item",
); );
assertEquals(error.errors.length, 2); assertEquals(error.errors.length, 2);
assertStringIncludes(error.errors[0].stack, "Error: Bad number: 1"); assertStringIncludes(error.errors[0].stack, "Error: Bad number: 1");

View File

@ -134,11 +134,21 @@ export async function retry<T>(
...opts, ...opts,
}; };
if (options.maxTimeout <= 0) throw new TypeError("maxTimeout is less than 0"); if (options.maxTimeout <= 0) {
if (options.minTimeout > options.maxTimeout) { throw new TypeError(
throw new TypeError("minTimeout is greater than maxTimeout"); `Cannot retry as 'maxTimeout' must be positive: current value is ${options.maxTimeout}`,
);
}
if (options.minTimeout > options.maxTimeout) {
throw new TypeError(
`Cannot retry as 'minTimeout' must be <= 'maxTimeout': current values 'minTimeout=${options.minTimeout}', 'maxTimeout=${options.maxTimeout}'`,
);
}
if (options.jitter > 1) {
throw new TypeError(
`Cannot retry as 'jitter' must be <= 1: current value is ${options.jitter}`,
);
} }
if (options.jitter > 1) throw new TypeError("jitter is greater than 1");
let attempt = 0; let attempt = 0;
while (true) { while (true) {

View File

@ -64,7 +64,7 @@ Deno.test(
maxTimeout: 100, maxTimeout: 100,
}), }),
TypeError, TypeError,
"minTimeout is greater than maxTimeout", "Cannot retry as 'minTimeout' must be <= 'maxTimeout': current values 'minTimeout=1000', 'maxTimeout=100'",
); );
}, },
); );
@ -78,7 +78,7 @@ Deno.test(
maxTimeout: -1, maxTimeout: -1,
}), }),
TypeError, TypeError,
"maxTimeout is less than 0", "Cannot retry as 'maxTimeout' must be positive: current value is -1",
); );
}, },
); );
@ -92,7 +92,7 @@ Deno.test(
jitter: 2, jitter: 2,
}), }),
TypeError, TypeError,
"jitter is greater than 1", "Cannot retry as 'jitter' must be <= 1: current value is 2",
); );
}, },
); );