diff --git a/addons/docs/src/frameworks/svelte/extractArgTypes.ts b/addons/docs/src/frameworks/svelte/extractArgTypes.ts index c560ce65b28b..d9374d2476c8 100644 --- a/addons/docs/src/frameworks/svelte/extractArgTypes.ts +++ b/addons/docs/src/frameworks/svelte/extractArgTypes.ts @@ -1,4 +1,5 @@ import { ArgTypes } from '@storybook/api'; +import { logger } from '@storybook/client-logger'; import { ArgTypesExtractor } from '../../lib/docgen'; @@ -33,19 +34,23 @@ type Docgen = { }; export const extractArgTypes: ArgTypesExtractor = (component) => { - // eslint-disable-next-line new-cap - const comp: ComponentWithDocgen = new component({ props: {} }); - // eslint-disable-next-line no-underscore-dangle - const docs = comp.__docgen; - - const results = createArgTypes(docs); - - return results; + try { + // eslint-disable-next-line new-cap + const comp: ComponentWithDocgen = new component({ props: {} }); + // eslint-disable-next-line no-underscore-dangle + const docgen = comp.__docgen; + if (docgen) { + return createArgTypes(docgen); + } + } catch (err) { + logger.log(`Error extracting argTypes: ${err}`); + } + return {}; }; -export const createArgTypes = (docs: Docgen) => { +export const createArgTypes = (docgen: Docgen) => { const results: ArgTypes = {}; - docs.data.forEach((item) => { + docgen.data.forEach((item) => { results[item.name] = { control: { type: parseType(item.type.type) }, name: item.name, diff --git a/examples/svelte-kitchen-sink/src/stories/error.stories.js b/examples/svelte-kitchen-sink/src/stories/error.stories.js new file mode 100644 index 000000000000..21be1c4add54 --- /dev/null +++ b/examples/svelte-kitchen-sink/src/stories/error.stories.js @@ -0,0 +1,14 @@ +import ErrorView from './views/ErrorView.svelte'; + +export default { + title: 'Error', + component: ErrorView, + parameters: { + chromatic: { disable: true }, + storyshots: { disable: true }, + }, +}; + +export const Error = () => ({ + Component: ErrorView, +}); diff --git a/examples/svelte-kitchen-sink/src/stories/views/ErrorView.svelte b/examples/svelte-kitchen-sink/src/stories/views/ErrorView.svelte new file mode 100644 index 000000000000..50847c1e169f --- /dev/null +++ b/examples/svelte-kitchen-sink/src/stories/views/ErrorView.svelte @@ -0,0 +1,4 @@ + \ No newline at end of file