Skip to content

Commit 4f6c7ec

Browse files
committed
handle patch errors
1 parent 34e18ba commit 4f6c7ec

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/scanElement.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import patches from './patches.js';
22
import markPatched from './markPatched.js';
33
import scanURL from './scanURL.js';
44

5+
function patchFailed(name, err) {
6+
console.error(`Patch ${name} failed! ${err}`);
7+
if (err.stack) {
8+
console.error(err.stack);
9+
}
10+
}
11+
512
export default async function scanElement(elem) {
613
if (!elem.classList || !elem.classList.contains) return;
714

@@ -28,7 +35,13 @@ export default async function scanElement(elem) {
2835
if (patch.applied(match)) continue;
2936
}
3037

31-
applications.push(patch.apply(match));
38+
try {
39+
const promise = Promise.resolve(patch.apply(match));
40+
const handled = promise.catch(err => patchFailed(patch.name, err));
41+
applications.push(handled);
42+
} catch (err) {
43+
patchFailed(patch.name, err);
44+
}
3245
}
3346
}
3447

0 commit comments

Comments
 (0)