Skip to content
Merged
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
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const identifier = [platform, arch, stdlib, abi].filter(c => c !== undefined &&
* Imports cpp bindings based on the current platform and architecture.
*/
// eslint-disable-next-line complexity
export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
export function importCppBindingsModule(): PrivateV8CpuProfilerBindings | undefined {
// If a binary path is specified, use that.
if (env['SENTRY_PROFILER_BINARY_PATH']) {
const envPath = env['SENTRY_PROFILER_BINARY_PATH'];
Expand Down Expand Up @@ -182,10 +182,16 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
}
}

return require(`./sentry_cpu_profiler-${identifier}.node`);
try {
return require(`./sentry_cpu_profiler-${identifier}.node`);
} catch (e) {
console.log(`[Profiling] Could not import binary: ${identifier}. Profiling does not work on non-LTS Node.js versions. Detailed Error:`);
console.log(e);
return undefined;
}
}

export const PrivateCpuProfilerBindings: PrivateV8CpuProfilerBindings = importCppBindingsModule();
export const PrivateCpuProfilerBindings: PrivateV8CpuProfilerBindings | undefined = importCppBindingsModule();

class Bindings implements V8CpuProfilerBindings {
public startProfiling(name: string): void {
Expand Down
Loading