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

Controls: Fix crashing when docgen extraction partially fails #26862

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions code/lib/core-events/src/errors/preview-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,22 @@ export class UnknownArgTypesError extends StorybookError {

readonly code = 1;

readonly documentation = 'https://github.com/storybookjs/storybook/issues/26606';

constructor(public data: { type: object; language: string }) {
super();
}

template() {
return `There was a failure when generating ArgTypes in ${
return dedent`There was a failure when generating detailed ArgTypes in ${
this.data.language
} for ${JSON.stringify(this.data.type)}
This type is either not supported or it is a bug in Storybook.
If you think this is a bug, please open an issue in Github.`;
} for:

${JSON.stringify(this.data.type, null, 2)}

so Storybook will fall back to a generic type description.

This type is either not supported or it is a bug in the docgen generation in Storybook.
If you think this is a bug, please detail it as much as possible in the Github issue.`;
}
}
11 changes: 8 additions & 3 deletions code/lib/docs-tools/src/argTypes/convert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import { convert as propTypesConvert } from './proptypes';

export const convert = (docgenInfo: DocgenInfo) => {
const { type, tsType, flowType } = docgenInfo;
if (type != null) return propTypesConvert(type);
if (tsType != null) return tsConvert(tsType as TSType);
if (flowType != null) return flowConvert(flowType as FlowType);
try {
if (type != null) return propTypesConvert(type);
if (tsType != null) return tsConvert(tsType as TSType);
if (flowType != null) return flowConvert(flowType as FlowType);
} catch (err) {
// if we can't convert the type, we'll just return null to fallback to a simple summary, and provide the error to the user
console.error(err);
}

return null;
};
Loading