-
Notifications
You must be signed in to change notification settings - Fork 143
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
[Themes] Add error overlay for theme upload failures #5208
Closed
jamesmengo
wants to merge
4
commits into
jm/_Themes_Add_error_tracking_for_theme_upload_results
from
jm/error_overlay
+63
−26
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ac149f9
Add uploadErrors property to theme file system
jamesmengo 26dd68b
Save asset upload failures during theme dev to uploadErrors map
jamesmengo 333b417
Render error overlay when themeFileSystem has upload errors
jamesmengo 762d5aa
PIVOT - Use existing errorPage to render error overlay
jamesmengo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
packages/theme/src/cli/utilities/theme-environment/hot-reload/error-page.ts
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,28 @@ | ||
interface Error { | ||
message: string | ||
code: string | ||
} | ||
|
||
export function getErrorPage(options: {title: string; header: string; errors: Error[]}) { | ||
const html = String.raw | ||
|
||
return html`<html> | ||
<head> | ||
<title>${options.title ?? 'Unknown error'}</title> | ||
</head> | ||
<body | ||
id="full-error-page" | ||
style="display: flex; flex-direction: column; align-items: center; padding-top: 20px; font-family: Arial" | ||
> | ||
<h1>${options.header}</h1> | ||
|
||
${options.errors | ||
.map( | ||
(error) => | ||
`<p>${error.message}</p> | ||
<pre>${error.code}</pre>`, | ||
) | ||
.join('')} | ||
</body> | ||
</html>` | ||
} |
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -45,6 +45,7 @@ const THEME_PARTITION_REGEX = { | |||||
|
||||||
export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOptions): ThemeFileSystem { | ||||||
const files = new Map<string, ThemeAsset>() | ||||||
const uploadErrors = new Map<string, string[]>() | ||||||
const unsyncedFileKeys = new Set<string>() | ||||||
const filterPatterns = { | ||||||
ignoreFromFile: [] as string[], | ||||||
|
@@ -147,12 +148,12 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti | |||||
|
||||||
const [result] = await bulkUploadThemeAssets(Number(themeId), [{key: fileKey, value: content}], adminSession) | ||||||
|
||||||
if (!result?.success) { | ||||||
throw new Error( | ||||||
result?.errors?.asset | ||||||
? `\n\n${result.errors.asset.map((error) => `- ${error}`).join('\n')}` | ||||||
: 'Response was not successful.', | ||||||
) | ||||||
if (result?.success) { | ||||||
uploadErrors.delete(fileKey) | ||||||
} else { | ||||||
const errors = result?.errors?.asset ?? ['Response was not successful.'] | ||||||
uploadErrors.set(fileKey, errors) | ||||||
throw new Error(errors.length === 1 ? errors[0] : errors.join('\n')) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we want to keep throwing the error here so that we output to the terminal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
> ['foo'].join(',')
'foo' |
||||||
} | ||||||
|
||||||
unsyncedFileKeys.delete(fileKey) | ||||||
|
@@ -223,6 +224,7 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti | |||||
root, | ||||||
files, | ||||||
unsyncedFileKeys, | ||||||
uploadErrors, | ||||||
ready: () => themeSetupPromise, | ||||||
delete: async (fileKey: string) => { | ||||||
files.delete(fileKey) | ||||||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered storing this inside of the
ThemeAsset
typeI chose to store it here because
- It is likely that we will update this and check if this is empty frequently. We want these operations to be fast and straightforward
Set
, and store the errors themselves on theThemeAsset
. I tried this and it felt clunky.ThemeAsset
, we'd need to get the asset, check if it exists, and update theerror
key