Skip to content

Commit

Permalink
Feedback refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Oct 11, 2024
1 parent 265d3e1 commit 8e8fef2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
16 changes: 7 additions & 9 deletions packages/theme/src/cli/utilities/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ export function renderThrownError(headline: string, error: Error | AbortError) {
* @param preset - The type of operation that failed.
* @returns A function that accepts an error and renders it.
*/
export function createRenderCatchError(resource: string, preset?: 'delete' | 'upload') {
let headline = resource

if (preset) {
headline =
preset === 'delete'
? `Failed to delete file "${resource}" from remote theme.`
: `Failed to upload file "${resource}" to remote theme.`
}
export function createSyncingCatchError(resource: string, preset?: 'delete' | 'upload') {
const headline =
{
delete: `Failed to delete file "${resource}" from remote theme.`,
upload: `Failed to upload file "${resource}" to remote theme.`,
default: resource,
}[preset ?? 'default'] ?? resource

return (error: Error) => {
renderThrownError(headline, error)
Expand Down
6 changes: 3 additions & 3 deletions packages/theme/src/cli/utilities/theme-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getPatternsFromShopifyIgnore,
} from './asset-ignore.js'
import {Notifier} from './notifier.js'
import {createRenderCatchError} from './errors.js'
import {createSyncingCatchError} from './errors.js'
import {DEFAULT_IGNORE_PATTERNS, timestampDateFormat} from '../constants.js'
import {glob, readFile, ReadOptions, fileExists, mkdir, writeFile, removeFile} from '@shopify/cli-kit/node/fs'
import {joinPath, basename, relativePath} from '@shopify/cli-kit/node/path'
Expand Down Expand Up @@ -163,7 +163,7 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti

return true
})
.catch(createRenderCatchError(fileKey, 'upload'))
.catch(createSyncingCatchError(fileKey, 'upload'))

emitEvent(eventName, {
fileKey,
Expand Down Expand Up @@ -200,7 +200,7 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti
unsyncedFileKeys.delete(fileKey)
outputSyncResult('delete', fileKey)
})
.catch(createRenderCatchError(fileKey, 'delete'))
.catch(createSyncingCatchError(fileKey, 'delete'))
}

const directoriesToWatch = new Set(
Expand Down
4 changes: 2 additions & 2 deletions packages/theme/src/cli/utilities/theme-uploader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {partitionThemeFiles} from './theme-fs.js'
import {rejectGeneratedStaticAssets} from './asset-checksum.js'
import {renderTasksToStdErr} from './theme-ui.js'
import {createRenderCatchError} from './errors.js'
import {createSyncingCatchError} from './errors.js'
import {AdminSession} from '@shopify/cli-kit/node/session'
import {Result, Checksum, Theme, ThemeFileSystem} from '@shopify/cli-kit/node/themes/types'
import {AssetParams, bulkUploadThemeAssets, deleteThemeAsset} from '@shopify/cli-kit/node/themes/api'
Expand Down Expand Up @@ -139,7 +139,7 @@ function buildDeleteJob(
.catch((error: Error) => {
failedDeleteAttempts++
if (failedDeleteAttempts > 3) throw error
createRenderCatchError(file.key, 'delete')(error)
createSyncingCatchError(file.key, 'delete')(error)
})
.finally(() => {
progress.current++
Expand Down

0 comments on commit 8e8fef2

Please sign in to comment.