You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There will be categories of errors (which will grow over time) and a base error class, which will hold metadata such as category, code and message. This will be useful when going through these errors in telemetry:
enumCategory{INIT='I',RUNTIME='R',COMPILE='C',// ... and many more}// StorybookError, to keep metadata in its object which can be classStorybookErrorextendsError{constructor(publiccategory: Category,publiccode: string,message: string){super(message);}}
Errors would all be objects created via a factory function, which could take care of message formatting, would provide a flag to send telemetry, a flag for documentation, and could be used to display warnings without having to instantiate errors:
functioncreate<T,Cextendsstring>({
category,
code,
template,
documentation,
telemetry,}: {category: Category;code: C;template(data: T): string;// either true or a link to a specific documentationdocumentation?: boolean|string;telemetry?: boolean;}): {code: C;error: (data: T)=>StorybookError;message: (data: T)=>string;}{constpage=documentation===true
? `https://storybook.js.org/error/${code}`
: typeofdocumentation==='string'
? documentation
: undefined;constmessage=documentation
? (data: T)=>`SB_${category}_${code} - ${template(data)}\n\nMore info: ${page}`
: (data: T)=>`SB_${category}_${code} - ${template(data)}`consterror=(data: T)=>{// telemetry would be injected globally and accessed to send errors if neededif(telemetry&&globalThis.telemetry){globalThis.telemetry({ code, category, data,message: message(data)});}returnnewStorybookError(category,code,message(data));};return{ code, error, message };}
Example of the creation of errors:
// --- definition --- //exportconstINSTALL_FAILURE=create({category: Category.INIT,code: '0001',// if linked is true, append code in sb errors pagelinked: true,template: ({ reason }: {reason: string})=>`Failed to install: ${reason}`,});exportconstMISSING_MAIN_JS=create({category: Category.COMPILE,code: '0001',// if linked is a string, use it instead of the default /error/<code> urllinked: 'https://storybook.js.org/docs/faq#common-issue-and-how-to-solve-it',template: ({ location }: {location: string})=>`Missing main.js file at ${location}`,});
Example of usage:
// --- usage --- //if('we detected a problem, ow no!'){// can be used in warning messages without having to instantiate the errorconstfoo=INSTALL_FAILURE.error({reason: 'Unsupported Vite version.'});// Failed to install: Unsupported Vite version. More info https://storybook.js.org/error/I0001console.warn(foo.message);}if('we detected a problem, ow no!'){// Missing main.js file at xyz. More info https://storybook.js.org/docs/faq#common-issue-and-how-to-solve-itthrowMISSING_MAIN_JS.error({location: 'main.js',});}
There will be categories of errors (which will grow over time) and a base error class, which will hold metadata such as category, code and message. This will be useful when going through these errors in telemetry:
Errors would all be objects created via a factory function, which could take care of message formatting, would provide a flag to send telemetry, a flag for documentation, and could be used to display warnings without having to instantiate errors:
Example of the creation of errors:
Example of usage:
Prototype
The text was updated successfully, but these errors were encountered: