mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
Controls: Fix crashing when docgen extraction partially fails
This commit is contained in:
parent
38afbe6902
commit
7e120a81c6
@ -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.`;
|
||||
}
|
||||
}
|
||||
|
@ -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…
x
Reference in New Issue
Block a user