Skip to content

Commit d8eaee9

Browse files
authored
ref: Log warning when fallback binary import fails (#39)
1 parent 9ff52e0 commit d8eaee9

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎src/index.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const identifier = [platform, arch, stdlib, abi].filter(c => c !== undefined &&
2424
* Imports cpp bindings based on the current platform and architecture.
2525
*/
2626
// eslint-disable-next-line complexity
27-
export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
27+
export function importCppBindingsModule(): PrivateV8CpuProfilerBindings | undefined {
2828
// If a binary path is specified, use that.
2929
if (env['SENTRY_PROFILER_BINARY_PATH']) {
3030
const envPath = env['SENTRY_PROFILER_BINARY_PATH'];
@@ -182,10 +182,16 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
182182
}
183183
}
184184

185-
return require(`./sentry_cpu_profiler-${identifier}.node`);
185+
try {
186+
return require(`./sentry_cpu_profiler-${identifier}.node`);
187+
} catch (e) {
188+
console.log(`[Profiling] Could not import binary: ${identifier}. Profiling does not work on non-LTS Node.js versions. Detailed Error:`);
189+
console.log(e);
190+
return undefined;
191+
}
186192
}
187193

188-
export const PrivateCpuProfilerBindings: PrivateV8CpuProfilerBindings = importCppBindingsModule();
194+
export const PrivateCpuProfilerBindings: PrivateV8CpuProfilerBindings | undefined = importCppBindingsModule();
189195

190196
class Bindings implements V8CpuProfilerBindings {
191197
public startProfiling(name: string): void {

0 commit comments

Comments
 (0)