Skip to content

Commit

Permalink
feat: if snyk fix throws unsupported error, show how to enable
Browse files Browse the repository at this point in the history
Link user to the docs on how to enable `snyk fix` beta
  • Loading branch information
lili2311 committed Aug 5, 2021
1 parent 48035f8 commit 34ea269
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/cli/commands/fix/validate-fix-command-is-supported.ts
Expand Up @@ -3,10 +3,10 @@ import * as Debug from 'debug';
import { getEcosystemForTest } from '../../../lib/ecosystems';

import { isFeatureFlagSupportedForOrg } from '../../../lib/feature-flags';
import { CommandNotSupportedError } from '../../../lib/errors/command-not-supported';
import { FeatureNotSupportedByEcosystemError } from '../../../lib/errors/not-supported-by-ecosystem';
import { Options, TestOptions } from '../../../lib/types';
import { AuthFailedError } from '../../../lib/errors';
import chalk from 'chalk';

const debug = Debug('snyk-fix');
const snykFixFeatureFlag = 'cliSnykFix';
Expand Down Expand Up @@ -35,7 +35,15 @@ export async function validateFixCommandIsSupported(
}

if (!snykFixSupported.ok) {
throw new CommandNotSupportedError('snyk fix', options.org || undefined);
const snykFixErrorMessage =
chalk.red(
`\`snyk fix\` is not supported ${
options.org ? `for org '${options.org}'` : ''
}.`,
) +
'\nSee documentation on how to enable this beta feature: https://support.snyk.io/hc/en-us/articles/4403417279505-Automatic-remediation-with-snyk-fix';
const unsupportedError = new Error(snykFixErrorMessage);
throw unsupportedError;
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion test/jest/system/lib/commands/fix/fix.spec.ts
Expand Up @@ -75,7 +75,7 @@ describe('snyk fix (system tests)', () => {
expect(err.message).toMatch('Command failed');
expect(err.code).toEqual(2);
expect(stdout).toMatch(
"`snyk fix` is not supported for org 'no-flag'",
"`snyk fix` is not supported for org 'no-flag'.\nSee documentation on how to enable this beta feature: https://support.snyk.io/hc/en-us/articles/4403417279505-Automatic-remediation-with-snyk-fix",
);
done();
},
Expand Down

0 comments on commit 34ea269

Please sign in to comment.