Skip to content

Commit c085195

Browse files
authored
Lenient LZ4 check (#298)
1 parent 2f10964 commit c085195

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', err);
11+
return undefined;
1212
}
13+
14+
if (err.code === 'MODULE_NOT_FOUND') {
15+
console.warn('LZ4 module not installed: Missing dependency', err);
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', err);
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', err);
26+
return undefined;
1327
}
1428
}
1529

0 commit comments

Comments
 (0)