Skip to content

Commit

Permalink
Merge pull request #26774 from storybookjs/reuben/flow-config-server-…
Browse files Browse the repository at this point in the history
…error-handling

Doc Tools: Signature Type Error Handling
  • Loading branch information
yannbf authored Apr 16, 2024
2 parents 1de3a41 + ffd17e8 commit 38afbe6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
18 changes: 18 additions & 0 deletions code/lib/core-events/src/errors/preview-errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, it, expect } from 'vitest';
import { UnknownArgTypesError } from './preview-errors';

describe('UnknownFlowArgTypesError', () => {
it('should correctly handle error with convertSig', () => {
const type = {
name: 'signature',
raw: "SomeType['someProperty']",
};

const message = `"There was a failure when generating ArgTypes in Typescript for {"name":"signature","raw":"SomeType['someProperty']"}
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."`;

const typeError = new UnknownArgTypesError({ type, language: 'Typescript' });
expect(typeError.message).toMatchInlineSnapshot(message);
});
});
19 changes: 19 additions & 0 deletions code/lib/core-events/src/errors/preview-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { StorybookError } from './storybook-error';
* to prevent manager and preview errors from having the same category and error code.
*/
export enum Category {
DOCS_TOOLS = 'DOCS-TOOLS',
PREVIEW_CLIENT_LOGGER = 'PREVIEW_CLIENT-LOGGER',
PREVIEW_CHANNELS = 'PREVIEW_CHANNELS',
PREVIEW_CORE_EVENTS = 'PREVIEW_CORE-EVENTS',
Expand Down Expand Up @@ -252,3 +253,21 @@ export class NextJsSharpError extends StorybookError {
`;
}
}

export class UnknownArgTypesError extends StorybookError {
readonly category = Category.DOCS_TOOLS;

readonly code = 1;

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

template() {
return `There was a failure when generating 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.`;
}
}
1 change: 1 addition & 0 deletions code/lib/docs-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
},
"dependencies": {
"@storybook/core-common": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/types": "workspace:*",
"@types/doctrine": "^0.0.3",
Expand Down
3 changes: 2 additions & 1 deletion code/lib/docs-tools/src/argTypes/convert/flow/convert.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UnknownArgTypesError } from '@storybook/core-events/preview-errors';
import type { SBType } from '@storybook/types';
import type { FlowType, FlowSigType, FlowLiteralType } from './types';

Expand All @@ -18,7 +19,7 @@ const convertSig = (type: FlowSigType) => {
value: values,
};
default:
throw new Error(`Unknown: ${type}`);
throw new UnknownArgTypesError({ type: type, language: 'Flow' });
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UnknownArgTypesError } from '@storybook/core-events/preview-errors';
import type { SBType } from '@storybook/types';
import type { TSType, TSSigType } from './types';
import { parseLiteral } from '../utils';
Expand All @@ -16,7 +17,7 @@ const convertSig = (type: TSSigType) => {
value: values,
};
default:
throw new Error(`Unknown: ${type}`);
throw new UnknownArgTypesError({ type, language: 'Typescript' });
}
};

Expand Down
1 change: 1 addition & 0 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5903,6 +5903,7 @@ __metadata:
dependencies:
"@babel/preset-react": "npm:^7.23.3"
"@storybook/core-common": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/preview-api": "workspace:*"
"@storybook/types": "workspace:*"
"@types/doctrine": "npm:^0.0.3"
Expand Down

0 comments on commit 38afbe6

Please sign in to comment.