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

Doc Tools: Signature Type Error Handling #26774

Merged
merged 12 commits into from
Apr 16, 2024
20 changes: 19 additions & 1 deletion code/lib/core-events/src/errors/server-errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest';
import { WebpackCompilationError } from './server-errors';
import dedent from 'ts-dedent';
import { UnknownArgTypesError, WebpackCompilationError } from './server-errors';

describe('WebpackCompilationError', () => {
it('should correctly handle error with stats.compilation.errors', () => {
Expand All @@ -14,3 +15,20 @@ describe('WebpackCompilationError', () => {
expect(webpackError.data.errors[1].message).toEqual('Error 2 message');
});
});

describe('UnknownFlowArgTypesError', () => {
it('should correctly handle error with Flow convertSig', () => {
const type = {
name: 'signature',
type: 'number',
signature: 1,
};
ethriel3695 marked this conversation as resolved.
Show resolved Hide resolved

const message = dedent`We detected a type {"name":"signature","type":"number","signature":1} in your configuration.
Your custom type does not match the TSFuncSigType or TSObjectSigType
Please check your Storybook configuration and ensure you have defined a valid type.`;

const typeError = new UnknownArgTypesError({ type });
expect(typeError.message).toEqual(message);
});
});
17 changes: 17 additions & 0 deletions code/lib/core-events/src/errors/server-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,20 @@ export class NoStatsForViteDevError extends StorybookError {
`;
}
}

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

readonly code = 1;

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

template() {
return dedent`We detected a type ${JSON.stringify(this.data.type)} in your configuration.
Your custom type does not match the TSFuncSigType or TSObjectSigType
Please check your Storybook configuration and ensure you have defined a valid type.
ethriel3695 marked this conversation as resolved.
Show resolved Hide resolved
`;
}
}
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/server-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 });
ethriel3695 marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UnknownArgTypesError } from '@storybook/core-events/server-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 });
ethriel3695 marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down