From 5641c2a0567cf8e75981bfc74110dcdce349860c Mon Sep 17 00:00:00 2001 From: Frank Steiler Date: Mon, 20 Oct 2025 15:32:28 +0200 Subject: [PATCH] node: Provide fallback for MachineIdentifier, in case shell is not available --- .../MachineIdentitfierAttributeProvider.ts | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/node/src/attributes/MachineIdentitfierAttributeProvider.ts b/packages/node/src/attributes/MachineIdentitfierAttributeProvider.ts index fac11035..fd2d9f4c 100644 --- a/packages/node/src/attributes/MachineIdentitfierAttributeProvider.ts +++ b/packages/node/src/attributes/MachineIdentitfierAttributeProvider.ts @@ -24,31 +24,35 @@ export class MachineIdentitfierAttributeProvider implements BacktraceAttributePr } public generateGuid() { - switch (process.platform) { - case 'win32': { - return execSync(this.COMMANDS['win32']) - .toString() - .match(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i)?.[0] - .toLowerCase(); - } - case 'darwin': { - return execSync(this.COMMANDS[process.platform]) - .toString() - .split('IOPlatformUUID')[1] - .split('\n')[0] - .replace(/=|\s+|"/gi, '') - .toLowerCase(); - } - case 'linux': - case 'freebsd': { - return execSync(this.COMMANDS[process.platform]) - .toString() - .replace(/\r+|\n+|\s+/gi, '') - .toLowerCase(); - } - default: { - return null; + try { + switch (process.platform) { + case 'win32': { + return execSync(this.COMMANDS['win32']) + .toString() + .match(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i)?.[0] + .toLowerCase(); + } + case 'darwin': { + return execSync(this.COMMANDS[process.platform]) + .toString() + .split('IOPlatformUUID')[1] + .split('\n')[0] + .replace(/=|\s+|"/gi, '') + .toLowerCase(); + } + case 'linux': + case 'freebsd': { + return execSync(this.COMMANDS[process.platform]) + .toString() + .replace(/\r+|\n+|\s+/gi, '') + .toLowerCase(); + } + default: { + return null; + } } + } catch { + return null } } }