Controls: Fix crashing when docgen extraction partially fails

This commit is contained in:
Yann Braga 2024-04-17 12:30:52 +02:00
parent 38afbe6902
commit 7e120a81c6
2 changed files with 19 additions and 7 deletions

View File

@ -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.`;
}
}

View File

@ -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;
};