Skip to content

Commit f433592

Browse files
authored
Merge pull request #4377 from snyk/chore/HEAD-82_add_warning
chore: check if the platform is supported
2 parents 1e9fcf6 + c2bd650 commit f433592

File tree

4 files changed

+207
-0
lines changed

4 files changed

+207
-0
lines changed

package-lock.json

Lines changed: 154 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"license": "Apache-2.0",
6161
"dependencies": {
6262
"@open-policy-agent/opa-wasm": "^1.6.0",
63+
"@sentry/node": "^7.34.0",
6364
"@snyk/cli-interface": "2.11.0",
6465
"@snyk/cloud-config-parser": "^1.14.5",
6566
"@snyk/code-client": "^4.15.0",

src/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { callHandlingUnexpectedErrors } from '../lib/unexpected-error';
22
import { EXIT_CODES } from './exit-codes';
3+
import { testPlatformSupport } from '../lib/common';
34

45
/**
56
* By using a dynamic import, we can add error handlers before evaluating any
67
* further modules. This way, if a module has errors, it'll be caught and
78
* handled as we expect.
89
*/
910
callHandlingUnexpectedErrors(async () => {
11+
testPlatformSupport();
1012
const { main } = await import('./main');
1113
await main();
1214
}, EXIT_CODES.ERROR);

src/lib/common.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import * as os from 'os';
2+
import * as alerts from './alerts';
3+
import * as Sentry from '@sentry/node';
4+
import * as version from './version';
5+
import * as analytics from './analytics/index';
6+
17
export async function sleep(ms: number): Promise<void> {
28
return new Promise((resolve) => setTimeout(resolve, ms));
39
}
@@ -6,3 +12,47 @@ export const reTryMessage =
612
'Tip: Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>';
713
export const contactSupportMessage =
814
'If the issue persists contact [email protected]';
15+
16+
export function testPlatformSupport() {
17+
const supportedPlatforms = [
18+
'darwin amd64',
19+
'darwin x64',
20+
'darwin arm64',
21+
'linux amd64',
22+
'linux x64',
23+
'linux arm64',
24+
'win32 amd64',
25+
'win32 x64',
26+
'win32 arm64',
27+
];
28+
29+
const currentPlatform = os.platform() + ' ' + os.arch();
30+
if (!supportedPlatforms.includes(currentPlatform)) {
31+
const platformWarning =
32+
'------------------------------- Warning -------------------------------\n' +
33+
' The current platform (' +
34+
currentPlatform +
35+
') is not supported by Snyk.\n' +
36+
' You may want to consider using docker to run Snyk.\n' +
37+
' If you experience errors please reach out to [email protected].\n' +
38+
'-----------------------------------------------------------------------';
39+
40+
alerts.registerAlerts([
41+
{
42+
type: 'warning',
43+
name: 'testPlatformSupport',
44+
msg: platformWarning,
45+
},
46+
]);
47+
48+
if (analytics.allowAnalytics()) {
49+
const sentryError = new Error('Unsupported Platform: ' + currentPlatform);
50+
Sentry.init({
51+
dsn:
52+
'https://[email protected]/4504599528079360',
53+
release: version.getVersion(),
54+
});
55+
Sentry.captureException(sentryError);
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)