Skip to content

Commit

Permalink
fix(kv): improve backoff error message and inline documentation (#27537)
Browse files Browse the repository at this point in the history
Ref: #27536
  • Loading branch information
kitsonk authored Jan 3, 2025
1 parent 89c92b8 commit 7cabd02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cli/tsc/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ declare namespace Deno {
* executions. Each element in the array represents the number of milliseconds
* to wait before retrying the execution. For example, `[1000, 5000, 10000]`
* means that a failed execution will be retried at most 3 times, with 1
* second, 5 seconds, and 10 seconds delay between each retry.
* second, 5 seconds, and 10 seconds delay between each retry. There is a
* limit of 5 retries and a maximum interval of 1 hour (3600000 milliseconds).
*
* @category Cloud
* @experimental
Expand Down
8 changes: 6 additions & 2 deletions ext/kv/01_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,19 @@ const maxQueueBackoffInterval = 60 * 60 * 1000;

function validateBackoffSchedule(backoffSchedule: number[]) {
if (backoffSchedule.length > maxQueueBackoffIntervals) {
throw new TypeError("Invalid backoffSchedule");
throw new TypeError(
`Invalid backoffSchedule, max ${maxQueueBackoffIntervals} intervals allowed`,
);
}
for (let i = 0; i < backoffSchedule.length; ++i) {
const interval = backoffSchedule[i];
if (
interval < 0 || interval > maxQueueBackoffInterval ||
NumberIsNaN(interval)
) {
throw new TypeError("Invalid backoffSchedule");
throw new TypeError(
`Invalid backoffSchedule, interval at index ${i} is invalid`,
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/kv_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1951,14 +1951,14 @@ dbTest("Invalid backoffSchedule", async (db) => {
await db.enqueue("foo", { backoffSchedule: [1, 1, 1, 1, 1, 1] });
},
TypeError,
"Invalid backoffSchedule",
"Invalid backoffSchedule, max 5 intervals allowed",
);
await assertRejects(
async () => {
await db.enqueue("foo", { backoffSchedule: [3600001] });
},
TypeError,
"Invalid backoffSchedule",
"Invalid backoffSchedule, interval at index 0 is invalid",
);
});

Expand Down

0 comments on commit 7cabd02

Please sign in to comment.