Skip to content

Lenient LZ4 check #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/utils/lz4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@ function tryLoadLZ4Module(): LZ4Module | undefined {
try {
return require('lz4'); // eslint-disable-line global-require
} catch (err) {
const isModuleNotFoundError = err instanceof Error && 'code' in err && err.code === 'MODULE_NOT_FOUND';
if (!isModuleNotFoundError) {
throw 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;
}
}

Expand Down
Loading