Skip to content

Commit 7cabd02

Browse files
authored
fix(kv): improve backoff error message and inline documentation (denoland#27537)
Ref: denoland#27536
1 parent 89c92b8 commit 7cabd02

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

cli/tsc/dts/lib.deno.unstable.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ declare namespace Deno {
293293
* executions. Each element in the array represents the number of milliseconds
294294
* to wait before retrying the execution. For example, `[1000, 5000, 10000]`
295295
* means that a failed execution will be retried at most 3 times, with 1
296-
* second, 5 seconds, and 10 seconds delay between each retry.
296+
* second, 5 seconds, and 10 seconds delay between each retry. There is a
297+
* limit of 5 retries and a maximum interval of 1 hour (3600000 milliseconds).
297298
*
298299
* @category Cloud
299300
* @experimental

ext/kv/01_db.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,19 @@ const maxQueueBackoffInterval = 60 * 60 * 1000;
7777

7878
function validateBackoffSchedule(backoffSchedule: number[]) {
7979
if (backoffSchedule.length > maxQueueBackoffIntervals) {
80-
throw new TypeError("Invalid backoffSchedule");
80+
throw new TypeError(
81+
`Invalid backoffSchedule, max ${maxQueueBackoffIntervals} intervals allowed`,
82+
);
8183
}
8284
for (let i = 0; i < backoffSchedule.length; ++i) {
8385
const interval = backoffSchedule[i];
8486
if (
8587
interval < 0 || interval > maxQueueBackoffInterval ||
8688
NumberIsNaN(interval)
8789
) {
88-
throw new TypeError("Invalid backoffSchedule");
90+
throw new TypeError(
91+
`Invalid backoffSchedule, interval at index ${i} is invalid`,
92+
);
8993
}
9094
}
9195
}

tests/unit/kv_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,14 +1951,14 @@ dbTest("Invalid backoffSchedule", async (db) => {
19511951
await db.enqueue("foo", { backoffSchedule: [1, 1, 1, 1, 1, 1] });
19521952
},
19531953
TypeError,
1954-
"Invalid backoffSchedule",
1954+
"Invalid backoffSchedule, max 5 intervals allowed",
19551955
);
19561956
await assertRejects(
19571957
async () => {
19581958
await db.enqueue("foo", { backoffSchedule: [3600001] });
19591959
},
19601960
TypeError,
1961-
"Invalid backoffSchedule",
1961+
"Invalid backoffSchedule, interval at index 0 is invalid",
19621962
);
19631963
});
19641964

0 commit comments

Comments
 (0)