Skip to content

Commit

Permalink
Merge pull request #22515 from storybookjs/fix/fix-error-throwing
Browse files Browse the repository at this point in the history
CLI: Throw errors instead of rejecting promises
  • Loading branch information
yannbf authored and shilman committed May 12, 2023
1 parent b7c145e commit 918eba9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 1 addition & 2 deletions code/lib/cli/src/generators/ANGULAR/index.ts
Expand Up @@ -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();
Expand Down
17 changes: 10 additions & 7 deletions code/lib/cli/src/initiate.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -161,12 +162,12 @@ const installStorybook = async <Project extends ProjectType>(
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(
Expand Down Expand Up @@ -200,7 +201,9 @@ const installStorybook = async <Project extends ProjectType>(
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);
}
};
Expand Down

0 comments on commit 918eba9

Please sign in to comment.