Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Feb 16, 2024
1 parent 21945ad commit a321a58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 0 additions & 1 deletion code/lib/cli/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
} from '@storybook/core-common';
import { automigrate } from './automigrate/index';
import { autoblock } from './autoblock/index';
import { PreCheckFailure } from './automigrate/types';

type Package = {
package: string;
Expand Down
4 changes: 2 additions & 2 deletions code/lib/core-common/src/utils/load-main-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { validateConfigurationFiles } from './validate-configuration-files';
import { readFile } from 'fs/promises';
import {
MainFileESMOnlyImportError,
MainFileFailedEvaluationError,
MainFileEvaluationError,
} from '@storybook/core-events/server-errors';

export async function loadMainConfig({
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function loadMainConfig({
throw out;
}

throw new MainFileFailedEvaluationError({
throw new MainFileEvaluationError({
location: relative(process.cwd(), mainJsPath),
error: e,
});
Expand Down
24 changes: 16 additions & 8 deletions code/lib/core-events/src/errors/server-errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold, gray, grey, white, yellow } from 'chalk';
import { bold, gray, grey, white, yellow, underline } from 'chalk';
import dedent from 'ts-dedent';
import { StorybookError } from './storybook-error';

Expand Down Expand Up @@ -421,18 +421,20 @@ export class MainFileESMOnlyImportError extends StorybookError {
if (this.data.line) {
message.push(
white(
`In your ${yellow(this.data.location)} file, this line threw an error: ${bold.cyan(
`In your ${yellow(this.data.location)} file, line ${bold.cyan(
this.data.num
)}, which looks like this:`
)} threw an error, which looks like this:`
),
grey(this.data.line)
);
}

message.push(
'',
white(`Convert the static import to an dynamic import where they are used.`),
white(`Example:`) + ' ' + gray(`await import(<your ESM only module>);`)
white(`Convert the static import to an dynamic import ${underline('where they are used')}.`),
white(`Example:`) + ' ' + gray(`await import(<your ESM only module>);`),
'',
'For more information, please read the documentation link below.'
);

return message.join('\n');
Expand All @@ -444,6 +446,8 @@ export class MainFileMissingError extends StorybookError {

readonly code = 6;

readonly stack = '';

public readonly documentation = 'https://storybook.js.org/docs/configure';

constructor(public data: { location: string }) {
Expand All @@ -460,22 +464,26 @@ export class MainFileMissingError extends StorybookError {
}
}

export class MainFileFailedEvaluationError extends StorybookError {
export class MainFileEvaluationError extends StorybookError {
readonly category = Category.CORE_SERVER;

readonly code = 7;

public readonly documentation = 'https://storybook.js.org/docs/configure';
readonly stack = '';

constructor(public data: { location: string; error: Error }) {
super();
}

template() {
const errorText = white(
(this.data.error.stack || this.data.error.message).replaceAll(process.cwd(), '')
);

return dedent`
Storybook couldn't evaluate your ${yellow(this.data.location)} file.
${this.data.error.message}
${errorText}
`;
}
}
Expand Down

0 comments on commit a321a58

Please sign in to comment.