From 34ea269012733b2744ae3314927bb27a382d6e32 Mon Sep 17 00:00:00 2001 From: ghe Date: Thu, 5 Aug 2021 12:08:58 +0100 Subject: [PATCH] feat: if `snyk fix` throws unsupported error, show how to enable Link user to the docs on how to enable `snyk fix` beta --- .../fix/validate-fix-command-is-supported.ts | 12 ++++++++++-- test/jest/system/lib/commands/fix/fix.spec.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cli/commands/fix/validate-fix-command-is-supported.ts b/src/cli/commands/fix/validate-fix-command-is-supported.ts index b9d78486b77..10af0ade2b6 100644 --- a/src/cli/commands/fix/validate-fix-command-is-supported.ts +++ b/src/cli/commands/fix/validate-fix-command-is-supported.ts @@ -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'; @@ -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; diff --git a/test/jest/system/lib/commands/fix/fix.spec.ts b/test/jest/system/lib/commands/fix/fix.spec.ts index fcce43708d6..384ea8375fb 100644 --- a/test/jest/system/lib/commands/fix/fix.spec.ts +++ b/test/jest/system/lib/commands/fix/fix.spec.ts @@ -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(); },