Skip to content

Commit 5641c2a

Browse files
committed
node: Provide fallback for MachineIdentifier, in case shell is not available
1 parent 39e1410 commit 5641c2a

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

packages/node/src/attributes/MachineIdentitfierAttributeProvider.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,35 @@ export class MachineIdentitfierAttributeProvider implements BacktraceAttributePr
2424
}
2525

2626
public generateGuid() {
27-
switch (process.platform) {
28-
case 'win32': {
29-
return execSync(this.COMMANDS['win32'])
30-
.toString()
31-
.match(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i)?.[0]
32-
.toLowerCase();
33-
}
34-
case 'darwin': {
35-
return execSync(this.COMMANDS[process.platform])
36-
.toString()
37-
.split('IOPlatformUUID')[1]
38-
.split('\n')[0]
39-
.replace(/=|\s+|"/gi, '')
40-
.toLowerCase();
41-
}
42-
case 'linux':
43-
case 'freebsd': {
44-
return execSync(this.COMMANDS[process.platform])
45-
.toString()
46-
.replace(/\r+|\n+|\s+/gi, '')
47-
.toLowerCase();
48-
}
49-
default: {
50-
return null;
27+
try {
28+
switch (process.platform) {
29+
case 'win32': {
30+
return execSync(this.COMMANDS['win32'])
31+
.toString()
32+
.match(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i)?.[0]
33+
.toLowerCase();
34+
}
35+
case 'darwin': {
36+
return execSync(this.COMMANDS[process.platform])
37+
.toString()
38+
.split('IOPlatformUUID')[1]
39+
.split('\n')[0]
40+
.replace(/=|\s+|"/gi, '')
41+
.toLowerCase();
42+
}
43+
case 'linux':
44+
case 'freebsd': {
45+
return execSync(this.COMMANDS[process.platform])
46+
.toString()
47+
.replace(/\r+|\n+|\s+/gi, '')
48+
.toLowerCase();
49+
}
50+
default: {
51+
return null;
52+
}
5153
}
54+
} catch {
55+
return null
5256
}
5357
}
5458
}

0 commit comments

Comments
 (0)