Skip to content

Commit

Permalink
fix: log when module loading fails after max tries (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Nov 14, 2022
1 parent 3111e85 commit b25b4db
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions deno/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { load } from "https://deno.land/x/eszip@v0.28.0/loader.ts";
import { LoadResponse } from "https://deno.land/x/eszip@v0.28.0/mod.ts";
import * as path from "https://deno.land/std@0.127.0/path/mod.ts";
import { retryAsync } from "https://deno.land/x/retry@v2.0.0/mod.ts";
import { isTooManyTries } from "https://deno.land/x/retry@v2.0.0/retry/tooManyTries.ts";

const inlineModule = (specifier: string, content: string): LoadResponse => {
return {
Expand Down Expand Up @@ -35,10 +36,17 @@ const loadWithRetry = (specifier: string, delay = 1000, maxTry = 3) => {
return load(specifier);
}

return retryAsync(() => load(specifier), {
delay,
maxTry,
});
try {
return retryAsync(() => load(specifier), {
delay,
maxTry,
});
} catch (error) {
if (isTooManyTries(error)) {
console.error(`Loading ${specifier} failed after ${maxTry} tries.`);
}
throw error;
}
};

export { inlineModule, loadFromVirtualRoot, loadWithRetry };

0 comments on commit b25b4db

Please sign in to comment.