Skip to content

Commit

Permalink
Merge pull request #4377 from snyk/chore/HEAD-82_add_warning
Browse files Browse the repository at this point in the history
chore: check if the platform is supported
  • Loading branch information
PeterSchafer committed Feb 1, 2023
2 parents 1e9fcf6 + c2bd650 commit f433592
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 0 deletions.
154 changes: 154 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"license": "Apache-2.0",
"dependencies": {
"@open-policy-agent/opa-wasm": "^1.6.0",
"@sentry/node": "^7.34.0",
"@snyk/cli-interface": "2.11.0",
"@snyk/cloud-config-parser": "^1.14.5",
"@snyk/code-client": "^4.15.0",
Expand Down
2 changes: 2 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { callHandlingUnexpectedErrors } from '../lib/unexpected-error';
import { EXIT_CODES } from './exit-codes';
import { testPlatformSupport } from '../lib/common';

/**
* By using a dynamic import, we can add error handlers before evaluating any
* further modules. This way, if a module has errors, it'll be caught and
* handled as we expect.
*/
callHandlingUnexpectedErrors(async () => {
testPlatformSupport();
const { main } = await import('./main');
await main();
}, EXIT_CODES.ERROR);
50 changes: 50 additions & 0 deletions src/lib/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import * as os from 'os';
import * as alerts from './alerts';
import * as Sentry from '@sentry/node';
import * as version from './version';
import * as analytics from './analytics/index';

export async function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Expand All @@ -6,3 +12,47 @@ export const reTryMessage =
'Tip: Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>';
export const contactSupportMessage =
'If the issue persists contact support@snyk.io';

export function testPlatformSupport() {
const supportedPlatforms = [
'darwin amd64',
'darwin x64',
'darwin arm64',
'linux amd64',
'linux x64',
'linux arm64',
'win32 amd64',
'win32 x64',
'win32 arm64',
];

const currentPlatform = os.platform() + ' ' + os.arch();
if (!supportedPlatforms.includes(currentPlatform)) {
const platformWarning =
'------------------------------- Warning -------------------------------\n' +
' The current platform (' +
currentPlatform +
') is not supported by Snyk.\n' +
' You may want to consider using docker to run Snyk.\n' +
' If you experience errors please reach out to support@snyk.io.\n' +
'-----------------------------------------------------------------------';

alerts.registerAlerts([
{
type: 'warning',
name: 'testPlatformSupport',
msg: platformWarning,
},
]);

if (analytics.allowAnalytics()) {
const sentryError = new Error('Unsupported Platform: ' + currentPlatform);
Sentry.init({
dsn:
'https://3e845233db8c4f43b4c4b9245f1d7bd6@o30291.ingest.sentry.io/4504599528079360',
release: version.getVersion(),
});
Sentry.captureException(sentryError);
}
}
}

0 comments on commit f433592

Please sign in to comment.