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

fix: Prevent parser indexer not letting other addon errors to throw #242

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/indexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '#utils/error/parser/extract/svelte';
import { LegacyTemplateNotEnabledError } from '#utils/error/legacy-api/index';
import { NoDestructuredDefineMetaCallError } from '#utils/error/parser/analyse/define-meta';
import { isStorybookSvelteCSFError } from '#utils/error';

export const createIndexer = (legacyTemplate: boolean): Indexer => ({
test: /\.svelte$/,
Expand Down Expand Up @@ -39,6 +40,11 @@ export const createIndexer = (legacyTemplate: boolean): Indexer => ({
throw new LegacyTemplateNotEnabledError(filename);
xeho91 marked this conversation as resolved.
Show resolved Hide resolved
}

// WARN: We can't use instance of `StorybookSvelteCSFError`, because is an _abstract_ class :sob:
if (isStorybookSvelteCSFError(error)) {
throw error;
}

throw new IndexerParseError();
xeho91 marked this conversation as resolved.
Show resolved Hide resolved
}
},
Expand Down
11 changes: 10 additions & 1 deletion src/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { SvelteAST } from '#parser/ast';
* and modified for this addon needs.
*/
export abstract class StorybookSvelteCSFError extends Error {
public static isStorybookCSFSvelteError = true;
public static packageName = pkg.name;
public static packageVersion = pkg.version;

Expand Down Expand Up @@ -80,7 +81,7 @@ export abstract class StorybookSvelteCSFError extends Error {
* Generates the error message along with additional documentation link (if applicable).
*/
get message() {
if(this.customMessage) {
if (this.customMessage) {
return this.customMessage;
}

Expand Down Expand Up @@ -178,3 +179,11 @@ export abstract class StorybookSvelteCSFError extends Error {
return `<Story name="${this.storyNameFromAttribute}" />`;
}
}

// WARN: We can't use `instanceof StorybookSvelteCSFError`, because is an _abstract_ class
export function isStorybookSvelteCSFError(error: unknown): error is StorybookSvelteCSFError {
return Boolean(
(Object.getPrototypeOf(error)?.constructor as typeof StorybookSvelteCSFError)
?.isStorybookCSFSvelteError
);
}
Loading