Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Throw errors instead of rejecting promises #22515

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions code/lib/cli/src/generators/ANGULAR/index.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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, isStorybookInstalled, detectLanguage, detectBuilder, detectPnp } from './detect';
import { commandLog, codeLog, paddedLog } from './helpers';
Expand Down Expand Up @@ -191,12 +192,12 @@ const installStorybook = async <Project extends ProjectType>(
commandLog('Adding Storybook support to your "Server" app\n')
);

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 @@ -230,7 +231,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