Skip to content

Commit

Permalink
re-word parser errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Jun 21, 2024
1 parent ae9ed1e commit 998e9cb
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 86 deletions.
113 changes: 58 additions & 55 deletions ERRORS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Errors

List of errors that can be thrown by this addon.
This document is a list of known errors that this addon throws.

## `PARSER_EXTRACT_SVELTE`

### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_1`
### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0001`

Parser couldn't find the Svelte component **[module tag]**.
No **[module context]** was found in the stories file.

This often happens if you call `defineMeta(...)` in a regular instance script (`<script>`) and not in a module script (`<script context="module">`), which is required.

Ensure the stories file which caused this error has the following initial code:

Expand All @@ -20,54 +22,52 @@ Ensure the stories file which caused this error has the following initial code:
</script>
```

[module tag]: https://svelte.dev/docs/svelte-components#script-context-module
[module context]: https://svelte.dev/docs/svelte-components#script-context-module

### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_2`
### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0002`

You have used **default or namespace import** from this addon package.
Our parser doesn't support it.
A **default or namespace import** was used to import from this addon package, which is not supported. Only named imports are supported (this only applies to imports from `@storybook/addon-svelte-csf`).

Change in your stories file which caused this error:
Change your import to a named import instead:

```diff
- import svelteCsf from "@storybook/addon-svelte-csf";
+ import { defineMeta } from "@storybook/addon-svelte-csf";
```

### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_3`
### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0003`

Parser couldn't find `defineMeta` import specifier from this addon package import inside the Svelte component **[module tag]**.
No import of `defineMeta` from this addon package was found in the **[module context]**.

You might have forgotten to import it:

```diff
<script context="module">
- import { } from "@storybook/addon-svelte-csf";
+ import { defineMeta } from "@storybook/addon-svelte-csf";
...
</script>
```

### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_4`

Parser couldn't find variable declaration with `defineMeta()` call inside the Svelte component **[module tag]**.
### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004`

You might have forgotten to declare it:
No variable declaration from the `defineMeta()` call was found. While you might have called `defineMeta()`, its result needs to be assigned to a variable:

```diff
<script context="module">
import { defineMeta } from "@storybook/addon-svelte-csf";

- defineMeta(...);
+ const { Story } = defineMeta({
+ // define your stories meta here
+ });
</script>
```

### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_5`
### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0005`

Parser couldn't find a component `Story` **destructured** from the variable declaration with `defineMeta()` call.
No **destructured** `Story` component was found in the variable declaration with the `defineMeta()` call.

You might have used it incorrectly like this:
The `Story` component might have been incorrectly created:

```diff
<script context="module">
Expand All @@ -78,35 +78,40 @@ You might have used it incorrectly like this:
</script>
```

### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_6`

Parser couldn't find or recognize the **first argument** of the `defineMeta()` call.
Make sure it is a valid **object expression** which follows an interface [`Meta` from `@storybook/svelte`](https://github.com/storybookjs/storybook/blob/a496ec48c708eed753a5251d55fa07947a869e62/code/renderers/svelte/src/public-types.ts#L21-L28).
### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0006`

You might have used code incorrectly like this:
The **first argument** to the `defineMeta()` call was invalid.
It must be a valid **object expression** with the same structure as [the Default export in CSF](https://storybook.js.org/docs/api/csf#default-export).

```diff
<script context="module">
- const Story = defineMeta();
- const { Story } = defineMeta();
+ const { Story } = defineMeta({
+ // define your stories meta here
+ title: 'Path/To/MyComponent',
+ component: MyComponent,
+ decorators: [ ... ],
+ parameters: { ... },
+ });
</script>
```

### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_7`
### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0007`

Parser couldn't find the snippet passed down to `<Story />` attribute _(prop)_ - `children` - at the root of HTML fragment in the stories file which caused this error.
A `<Story>` component received an invalid `children` prop. If set, the `children` prop must be a reference to a [snippet](https://svelte-5-preview.vercel.app/docs/snippets) defined in the root scope file. Eg.:

Its trying to extract the snippet body as a stringified raw code for the Story source code.
```svelte
{#snippet template()}
<span>🚀</span>
{/snippet}
<!-- TODO: Link to the docs might need updating once Svelte 5 is released -->
<Story name="Rocket" children={template} />
```

Ensure you're using [Svelte `v5` feature **snippet** correctly](https://svelte-5-preview.vercel.app/docs/snippets).
This error indicates that the `children` prop was passed, but it was not correctly referencing a snippet.

### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_8`
### `SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0008`

Parser doesn't recognize or cannot find the snippet identifier passed as an first argument to this addon's feature `setTemplate()` function.
`setTemplate()` was called to set a default snippet, but the argument passed was not a reference to a root-level snippet in the file.

Below is a demonstration of correct usage:

Expand All @@ -120,15 +125,13 @@ Below is a demonstration of correct usage:
{/snippet}
```

Perhaps you've made a typo?

## `PARSER_EXTRACT_COMPILED`

> [!NOTE]:
> **For maintainers**: Those errors are less likely caused by the user, but rather a bug with parsing on our end on the
> compiled output.
### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_1`
### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0001`

Parser couldn't find `defineMeta` import specifier in the compiled output.

Expand All @@ -138,7 +141,7 @@ If you see this error, please report it using the link below:
While you create an issue, please provide original code of the stories file that caused this error.
It will help us investigate the occurred issue better.

### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_2`
### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0002`

Parser couldn't find a variable declaration with `defineMeta` call in the compiled output.

Expand All @@ -148,7 +151,7 @@ If you see this error, please report it using the link below:
While you create an issue, please provide original code of the stories file that caused this error.
It will help us investigate the occurred issue better.

### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_3`
### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0003`

Parser couldn't find the `export default` in the compiled output.

Expand All @@ -158,7 +161,7 @@ If you see this error, please report it using the link below:
While you create an issue, please provide original code of the stories file that caused this error.
It will help us investigate the occurred issue better.

### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_4`
### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0004`

Parser couldn't find a 'Story' identifier in the compiled output.

Expand All @@ -168,7 +171,7 @@ If you see this error, please report it using the link below:
While you create an issue, please provide original code of the stories file that caused this error.
It will help us investigate the occurred issue better.

### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_5`
### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0005`

Parser couldn't find a main function component for the `*.stories.svelte` file in the compiled output.

Expand All @@ -178,7 +181,7 @@ If you see this error, please report it using the link below:
While you create an issue, please provide original code of the stories file that caused this error.
It will help us investigate the occurred issue better.

### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_6`
### `SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0006`

Parser failed to extract compiled Story component attributes _(aka props)_ as object expression.

Expand All @@ -190,7 +193,7 @@ It will help us investigate the occurred issue better.

## `PARSER_ANALYSE_DEFINE_META`

### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_1`
### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_0001`

Our parser spotted an invalid schema on the `component` entry.
It expected an identifier to a Svelte component but got something else.
Expand All @@ -209,7 +212,7 @@ Ensure you're using the correct syntax, following the example above:
</script>
```

### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_2`
### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_0002`

Our parser spotted an invalid schema on the variable declaration from the `defineMeta` call.
You most likely forgot to destructure the return value.
Expand All @@ -221,7 +224,7 @@ You most likely forgot to destructure the return value.
});
```

### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_3`
### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_0003`

Our parser couldn't find auto-destructured `meta` identifier from the return value of `defineMeta()` in the compiled
output.
Expand All @@ -232,7 +235,7 @@ If you see this error, please report it using the link below:
While you create an issue, please provide original code of the stories file that caused this error.
It will help us investigate the occurred issue better.

### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_4`
### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_0004`

Our parser spotted an invalid schema on one of entries in the `defineMeta({ ... })` first argument.
Expected a **static string literal**, but got something else.
Expand All @@ -245,7 +248,7 @@ Those known and common keys should have a **static** string literal as value:
Do not use any function generating those values, because our parser doesn't know what those values return while
analysing the source code.

### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_5`
### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_0005`

Our parser spotted an invalid schema on one of entries in the `defineMeta({ ... })` first argument.
Expected an **array expression** `[/* items... */]`, but got something else.
Expand All @@ -254,7 +257,7 @@ Those known and common keys should be an array expression as value:

- **tags**

### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_6`
### `SB_SVELTE_CSF_PARSER_ANALYSE_DEFINE_META_0006`

Our parser spotted an invalid schema on one of entries in the `defineMeta({ ... })` first argument.

Expand All @@ -264,7 +267,7 @@ Those known keys should have array expression as value with only **static string

## `PARSER_ANALYSE_STORY`

### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_1`
### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0001`

Our parser found an invalid schema on an attribute _(prop)_ in one of `<Story />`.
A **static literal string** was expected but found something else.
Expand All @@ -284,7 +287,7 @@ Examples:
<Story exportName="MyComponent" />
```

### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_2`
### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0002`

Our parser found an invalid schema on an attribute _(prop)_ in one of `<Story />`.
An **array expression _(`[]`)_** was expected but found something else.
Expand All @@ -293,7 +296,7 @@ Those known and common attributes should be an **array expression** _(`[]`)_ as

- **tags**

### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_3`
### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0003`

Our parser found an invalid schema on an attribute _(prop)_ in one of `<Story />`.
An **array expression _(`[]`)_ with static literal strings as items** was expected but found something else.
Expand All @@ -308,7 +311,7 @@ Example:
<Story tags={['autodocs']} />
```

### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_4`
### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0004`

Our parser couldn't find an attribute _(prop)_ `name` or `exportName` in one of `<Story />` components.

Expand All @@ -320,15 +323,15 @@ Please ensure that every `<Story />` component uses one of these attributes, see
<Story exportName="MyStory" />
```

### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_5`
### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0005`

Our parser found an invalid attribute - `exportName` - _(prop)_ value in one of `<Story />` component.

**It must be a valid JavaScript variable name.**
It must start with a letter, `$` or `_`, followed by letters, numbers, `$` or `_`.
Reserved words like `default` are also not allowed (see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words>)

### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_6`
### `SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0006`

Our parser found a duplicate value of `exportName` attribute _(prop)_ between two `<Story />` components.

Expand All @@ -341,7 +344,7 @@ You can fix this collision by providing a unique `exportName`` prop with`<Story

## `COMPILER`

### `SB_SVELTE_CSF_COMPILER_1`
### `SB_SVELTE_CSF_COMPILER_0001`

There was an issue with code transformation on our side.
The parser tried to find `parameters` either in `defineMeta({})` entries or in `Story` _(compiled)_ props.
Expand All @@ -352,7 +355,7 @@ If you see this error, please report it using the link below:
While you create an issue, please provide original code of the stories file that caused this error.
It will help us investigate the occurred issue better.

### `SB_SVELTE_CSF_COMPILER_2`
### `SB_SVELTE_CSF_COMPILER_0002`

Our parser spotted an invalid schema on the property `parameters.docs` either in `defineMeta ({})` entries or in `Story` _(compiled)_ props.
It was expected to be an **object expression** as value, but got something else.
Expand All @@ -364,7 +367,7 @@ Please report it using the link below:
While you create an issue, please provide original code of the stories file that caused this error.
It will help us investigate the occurred issue better.

### `SB_SVELTE_CSF_COMPILER_3`
### `SB_SVELTE_CSF_COMPILER_0003`

Our parser spotted an invalid schema on the property `parameters.docs.description` either in `defineMeta ({})` entries or in `Story` _(compiled)_ props.
It was expected to be an **object expression** as value, but got something else.
Expand Down
Loading

0 comments on commit 998e9cb

Please sign in to comment.