From 918eba9601b2cf0d7e8b1aaa3037e4c22d51c0a9 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Thu, 11 May 2023 19:45:08 +0200 Subject: [PATCH] Merge pull request #22515 from storybookjs/fix/fix-error-throwing CLI: Throw errors instead of rejecting promises --- code/lib/cli/src/generators/ANGULAR/index.ts | 3 +-- code/lib/cli/src/initiate.ts | 17 ++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/code/lib/cli/src/generators/ANGULAR/index.ts b/code/lib/cli/src/generators/ANGULAR/index.ts index 361b93107370..665002dfac60 100644 --- a/code/lib/cli/src/generators/ANGULAR/index.ts +++ b/code/lib/cli/src/generators/ANGULAR/index.ts @@ -28,10 +28,9 @@ const generator: Generator<{ projectName: string }> = async ( const angularJSON = new AngularJSON(); if (angularJSON.projectsWithoutStorybook.length === 0) { - paddedLog( + throw new Error( 'Every project in your workspace is already set up with Storybook. There is nothing to do!' ); - return Promise.reject(); } const angularProjectName = await angularJSON.getProjectName(); diff --git a/code/lib/cli/src/initiate.ts b/code/lib/cli/src/initiate.ts index b588b81eece1..62797d5db756 100644 --- a/code/lib/cli/src/initiate.ts +++ b/code/lib/cli/src/initiate.ts @@ -4,6 +4,7 @@ import prompts from 'prompts'; import { telemetry } from '@storybook/telemetry'; import { withTelemetry } from '@storybook/core-server'; +import dedent from 'ts-dedent'; import { installableProjectTypes, ProjectType } from './project_types'; import { detect, @@ -161,12 +162,12 @@ const installStorybook = async ( commandLog('Adding Storybook support to your "Server" app') ); - case ProjectType.NX /* NX */: - paddedLog( - 'We have detected Nx in your project. Please use `nx g @nrwl/storybook:configuration` to add Storybook to your project.' - ); - paddedLog('For more information, please see https://nx.dev/packages/storybook'); - return Promise.reject(); + case ProjectType.NX: + throw new Error(dedent` + We have detected Nx in your project. Please use "nx g @nrwl/storybook:configuration" to add Storybook to your project. + + For more information, please see https://nx.dev/packages/storybook + `); case ProjectType.SOLID: return solidGenerator(packageManager, npmOptions, generatorOptions).then( @@ -200,7 +201,9 @@ const installStorybook = async ( try { return await runGenerator(); } catch (err) { - logger.error(`\n ${chalk.red(err.stack)}`); + if (err?.stack) { + logger.error(`\n ${chalk.red(err.stack)}`); + } throw new HandledError(err); } };