show more info in js rewrite err

This commit is contained in:
Toshit Chawda 2024-12-13 20:30:43 -08:00
parent 8ad714332a
commit 174375be1b
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
2 changed files with 17 additions and 10 deletions

View file

@ -26,15 +26,22 @@ function rewriteJsWrapper(
): string | ArrayBuffer {
let out: RewriterOutput;
const before = performance.now();
if (typeof input === "string") {
out = rewrite_js(input, meta.base.href, url || "(unknown)", $scramjet);
} else {
out = rewrite_js_from_arraybuffer(
new Uint8Array(input),
meta.base.href,
url || "(unknown)",
$scramjet
);
try {
if (typeof input === "string") {
out = rewrite_js(input, meta.base.href, url || "(unknown)", $scramjet);
} else {
out = rewrite_js_from_arraybuffer(
new Uint8Array(input),
meta.base.href,
url || "(unknown)",
$scramjet
);
}
} catch (err) {
let err1 = err as Error;
console.error("failed rewriting js for", url, err1, input);
err1.message = `failed rewriting js for "${url}": ${err1.message}`;
throw err1;
}
const after = performance.now();
const { js, errors, duration } = out;