forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request storybookjs#21114 from storybookjs/20663-coalesce-…
…errors Core: Coalesce multiple indexing errors into one
- Loading branch information
Showing
8 changed files
with
204 additions
and
106 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...stories/stories-mdx/csf-in-mdx.stories.js → ...ies/stories-mdx/csf-in-mdx.non-stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
code/addons/docs/template/stories/stories-mdx/csf-in-mdx.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import slash from 'slash'; | ||
|
||
export class IndexingError extends Error { | ||
importPaths: string[]; | ||
|
||
constructor(message: string, importPaths: string[], stack?: string) { | ||
super(); | ||
this.message = message; | ||
this.importPaths = importPaths; | ||
if (stack) { | ||
this.stack = stack; | ||
} | ||
} | ||
|
||
pathsString() { | ||
if (this.importPaths.length === 1) { | ||
return `${slash(this.importPaths[0])}`; | ||
} | ||
|
||
return `${this.importPaths.map(slash).join(',')}`; | ||
} | ||
|
||
toString() { | ||
return `${this.pathsString()}: ${this.message}`; | ||
} | ||
} | ||
|
||
export class MultipleIndexingError extends Error { | ||
constructor(public indexingErrors: IndexingError[]) { | ||
super(); | ||
|
||
if (this.indexingErrors.length === 0) throw new Error('Unexpected empty error list'); | ||
|
||
if (this.indexingErrors.length === 1) { | ||
const [err] = this.indexingErrors; | ||
this.message = `Unable to index ${err.pathsString()}`; | ||
} else { | ||
this.message = `Unable to index files:\n${this.indexingErrors | ||
.map((err) => `- ${err}`) | ||
.join('\n')}`; | ||
} | ||
} | ||
|
||
toString() { | ||
if (this.indexingErrors.length === 1) { | ||
return `${this.message}:\n ${this.indexingErrors[0].stack}`; | ||
} | ||
|
||
return this.message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.