Skip to content

Commit 8ab55c0

Browse files
committed
Make lz4 module loading more lenient
1 parent 2f10964 commit 8ab55c0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/utils/lz4.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@ function tryLoadLZ4Module(): LZ4Module | undefined {
66
try {
77
return require('lz4'); // eslint-disable-line global-require
88
} catch (err) {
9-
const isModuleNotFoundError = err instanceof Error && 'code' in err && err.code === 'MODULE_NOT_FOUND';
10-
if (!isModuleNotFoundError) {
11-
throw err;
9+
if (!(err instanceof Error) || !('code' in err)) {
10+
console.warn('Unexpected error loading LZ4 module: Invalid error object');
11+
return undefined;
1212
}
13+
14+
if (err.code === 'MODULE_NOT_FOUND') {
15+
console.warn('LZ4 module not installed: Missing dependency');
16+
return undefined;
17+
}
18+
19+
if (err.code === 'ERR_DLOPEN_FAILED') {
20+
console.warn('LZ4 native module failed to load: Architecture or version mismatch');
21+
return undefined;
22+
}
23+
24+
// If it's not a known error, return undefined
25+
console.warn('Unknown error loading LZ4 module: Unhandled error code');
26+
return undefined;
1327
}
1428
}
1529

0 commit comments

Comments
 (0)