mirror of
https://github.com/denoland/std.git
synced 2024-11-21 12:40:03 +00:00
refactor(async): align the error messages to the style guide (#5758)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
parent
46b3961833
commit
833a24f088
@ -2,7 +2,8 @@
|
||||
// This module is browser compatible.
|
||||
|
||||
/** 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
|
||||
|
@ -38,7 +38,7 @@ Deno.test("pooledMap() handles errors", async () => {
|
||||
}
|
||||
},
|
||||
AggregateError,
|
||||
"Threw while mapping.",
|
||||
"Cannot complete the mapping as an error was thrown from an item",
|
||||
);
|
||||
assertEquals(error.errors.length, 2);
|
||||
assertStringIncludes(error.errors[0].stack, "Error: Bad number: 1");
|
||||
|
@ -134,11 +134,21 @@ export async function retry<T>(
|
||||
...opts,
|
||||
};
|
||||
|
||||
if (options.maxTimeout <= 0) throw new TypeError("maxTimeout is less than 0");
|
||||
if (options.minTimeout > options.maxTimeout) {
|
||||
throw new TypeError("minTimeout is greater than maxTimeout");
|
||||
if (options.maxTimeout <= 0) {
|
||||
throw new TypeError(
|
||||
`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;
|
||||
while (true) {
|
||||
|
@ -64,7 +64,7 @@ Deno.test(
|
||||
maxTimeout: 100,
|
||||
}),
|
||||
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,
|
||||
}),
|
||||
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,
|
||||
}),
|
||||
TypeError,
|
||||
"jitter is greater than 1",
|
||||
"Cannot retry as 'jitter' must be <= 1: current value is 2",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user