forked from databricks/databricks-sql-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlz4.ts
More file actions
30 lines (24 loc) · 906 Bytes
/
lz4.ts
File metadata and controls
30 lines (24 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type LZ4Namespace from 'lz4';
type LZ4Module = typeof LZ4Namespace;
function tryLoadLZ4Module(): LZ4Module | undefined {
try {
return require('lz4'); // eslint-disable-line global-require
} catch (err) {
if (!(err instanceof Error) || !('code' in err)) {
console.warn('Unexpected error loading LZ4 module: Invalid error object', err);
return undefined;
}
if (err.code === 'MODULE_NOT_FOUND') {
console.warn('LZ4 module not installed: Missing dependency', err);
return undefined;
}
if (err.code === 'ERR_DLOPEN_FAILED') {
console.warn('LZ4 native module failed to load: Architecture or version mismatch', err);
return undefined;
}
// If it's not a known error, return undefined
console.warn('Unknown error loading LZ4 module: Unhandled error code', err);
return undefined;
}
}
export default tryLoadLZ4Module();