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 1 commit
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
17 changes: 16 additions & 1 deletion src/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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 +178,18 @@ export abstract class StorybookSvelteCSFError extends Error {
return `<Story name="${this.storyNameFromAttribute}" />`;
}
}

// WARN: We can't use instance of `StorybookSvelteCSFError`, because is an _abstract_ class :sob:
export function isStorybookSvelteCSFError(error: unknown) {
if (typeof error !== 'object' || error === null) {
return false;
}

for (const key of ['category', 'code', 'data', 'documentation', 'fullErrorCode', 'template']) {
xeho91 marked this conversation as resolved.
Show resolved Hide resolved
if (!Object.hasOwn(error, key)) {
return false;
}
}

return true;
}
Loading