From eee06005ab54c697724382e8840a51dcda58ad02 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 28 Jul 2023 18:27:52 +0200 Subject: [PATCH 01/28] add new errors framework --- code/lib/core-events/package.json | 42 +++++- code/lib/core-events/src/errors/README.md | 137 ++++++++++++++++++ .../src/errors/define-error.test.ts | 115 +++++++++++++++ .../core-events/src/errors/define-error.ts | 77 ++++++++++ .../core-events/src/errors/manager-errors.ts | 19 +++ .../src/errors/message-reference.png | Bin 0 -> 156646 bytes .../core-events/src/errors/preview-errors.ts | 22 +++ .../core-events/src/errors/server-errors.ts | 16 ++ code/lib/core-events/src/index.ts | 2 + code/yarn.lock | 1 + 10 files changed, 430 insertions(+), 1 deletion(-) create mode 100644 code/lib/core-events/src/errors/README.md create mode 100644 code/lib/core-events/src/errors/define-error.test.ts create mode 100644 code/lib/core-events/src/errors/define-error.ts create mode 100644 code/lib/core-events/src/errors/manager-errors.ts create mode 100644 code/lib/core-events/src/errors/message-reference.png create mode 100644 code/lib/core-events/src/errors/preview-errors.ts create mode 100644 code/lib/core-events/src/errors/server-errors.ts diff --git a/code/lib/core-events/package.json b/code/lib/core-events/package.json index 711937e16a78..ccd673c3eb2b 100644 --- a/code/lib/core-events/package.json +++ b/code/lib/core-events/package.json @@ -20,6 +20,22 @@ }, "license": "MIT", "sideEffects": false, + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "preview-errors": [ + "dist/errors/preview-errors.d.ts" + ], + "manager-errors": [ + "dist/errors/manager-errors.d.ts" + ], + "server-errors": [ + "dist/errors/server-errors.d.ts" + ] + } + }, "exports": { ".": { "types": "./dist/index.d.ts", @@ -27,6 +43,24 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, + "./preview-errors": { + "types": "./dist/errors/preview-errors.d.ts", + "node": "./dist/errors/preview-errors.js", + "require": "./dist/errors/preview-errors.js", + "import": "./dist/errors/preview-errors.mjs" + }, + "./manager-errors": { + "types": "./dist/errors/manager-errors.d.ts", + "node": "./dist/errors/manager-errors.js", + "require": "./dist/errors/manager-errors.js", + "import": "./dist/errors/manager-errors.mjs" + }, + "./server-errors": { + "types": "./dist/errors/server-errors.d.ts", + "node": "./dist/errors/server-errors.js", + "require": "./dist/errors/server-errors.js", + "import": "./dist/errors/server-errors.mjs" + }, "./package.json": "./package.json" }, "main": "./dist/index.js", @@ -43,6 +77,9 @@ "check": "../../../scripts/prepare/check.ts", "prep": "../../../scripts/prepare/bundle.ts" }, + "dependencies": { + "ts-dedent": "^2.0.0" + }, "devDependencies": { "typescript": "~4.9.3" }, @@ -51,7 +88,10 @@ }, "bundler": { "entries": [ - "./src/index.ts" + "./src/index.ts", + "./src/errors/preview-errors.ts", + "./src/errors/manager-errors.ts", + "./src/errors/server-errors.ts" ] }, "gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae17" diff --git a/code/lib/core-events/src/errors/README.md b/code/lib/core-events/src/errors/README.md new file mode 100644 index 000000000000..bea8eea63b6f --- /dev/null +++ b/code/lib/core-events/src/errors/README.md @@ -0,0 +1,137 @@ +# Storybook Errors + +Storybook provides a utility to manage errors thrown from it. Storybook errors reside in this package and are categorized into: + +1. **[Preview errors](./preview-errors.ts)** + - Errors which occur in the preview area of Storybook + - e.g. Rendering issues, etc. + - available in `@storybook/core-events/preview-errors` +2. **[Manager errors](./manager-errors.ts)** + - Errors which occur in the manager area of Storybook + - e.g. Sidebar, addons, Storybook UI, Storybook router, etc. + - available in `@storybook/core-events/manager-errors` +3. **[Server errors](./server-errors.ts)** + - Any Errors that happen in node + - e.g. Storybook init command, building in prod, building in dev, etc. + - available in `@storybook/core-events/server-errors` + +## How to create errors + +First, find which file your error should be part of, based on the criteria above. +Second use the `defineError` function to define custom errors with specific codes and categories for use within the Storybook codebase. Below is the detailed API documentation for this function: + +### Function Signature + +```typescript +export function defineError