-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4377 from snyk/chore/HEAD-82_add_warning
chore: check if the platform is supported
- Loading branch information
Showing
4 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
@@ -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 [email protected]'; | ||
|
||
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 [email protected].\n' + | ||
'-----------------------------------------------------------------------'; | ||
|
||
alerts.registerAlerts([ | ||
{ | ||
type: 'warning', | ||
name: 'testPlatformSupport', | ||
msg: platformWarning, | ||
}, | ||
]); | ||
|
||
if (analytics.allowAnalytics()) { | ||
const sentryError = new Error('Unsupported Platform: ' + currentPlatform); | ||
Sentry.init({ | ||
dsn: | ||
'https://[email protected]/4504599528079360', | ||
release: version.getVersion(), | ||
}); | ||
Sentry.captureException(sentryError); | ||
} | ||
} | ||
} |